I want to get XML data in XSL

Asked 2 years ago, Updated 2 years ago, 95 views

Hi, nice to meet you.Let me ask you a question.
Programming with XML+XSLT

Suppose you have the following XML:

<DATA>
    <F1>a</F1>
    <F2>Yes>/F2>
    <F3> U</F3>
    <F4>E</F4>
    <F5> Oh;/F5>
    <F1> or </F1>
    <F2>ki </F2>
    <F3>Ku</F3>
    <F4>Ke </F4>
    <F5>here>/F5>
    <F1>OK;/F1>
    <F2>Sh </F2>
    <F3>Su</F3>
    <F4>se>/F4>
    <F5> and </F5>
</DATA>

Among them, I am worried because I don't know how to write xpath to get only F3 data under F1=' or ' (in this case, or ).
Could you please let me know if anyone knows?
Thank you in advance.

xsl xpath

2022-09-30 14:55

2 Answers

If @user20662 is asking this question in the XPath 1.0 world like Windows+MSXML, @pgho's answer would be fine, but since the world is already moving up to XPath 3.0, what would XPath 2.0 be like at least?It's no use knowing that

As @sayuri pointed out, using //F1[text()=' or ']/following-sibling::F3/text() in XPath 2.0 will select two text nodes (tried on oXygen 18.1) so that the version of Xpath you want to use will work even if the version goes up, /folding][1][:'/folding=1]

Results of execution in Xpath 2.0

If you use Xpath 2.0 or higher, wouldn't it be appropriate to use string(/DATA/F1[string(.)eq']/following-sibling::F3[1])?

  • Return xs:string is more appropriate to get "ku" than text(). (Actually, it's unlikely to use it like as="text()" on XSLT style sheets that use XPath2.0.
  • Use the value comparison operator "eq" to specify a string comparison instead of the general comparison operator "=" to compare sequences.

The result is "ku" returned as a value as follows.

Description in Xpath 2.0

For your information,


2022-09-30 14:55

As a way of thinking,

The connection is as follows:

//F1[text()=' or ']/following-sibling::F3/text()


2022-09-30 14:55

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.