Is it possible with XPath to get a concatenated view of all the children of a node? I am looking for something like the JQuery.html () method.
For example, if I have the following XML:
<h3 class="title"> <span class="content">this</span> <span class="content"> is</span> <span class="content"> some</span> <span class="content"> text</span> </h3>
I need an XPath request for βh3 [@ class = 'title']β that would give me βthis is some textβ.
This is a real question, but if more context / background is useful, here it is: I am using XPath and I used this post to help me write some XSL complex. My original XML is as follows.
<h3 class="title">Title</h3> <p> <span class="content">Some</span> <span class="content"> text</span> <span class="content"> for</span> <span class="content"> this</span> <span class="content"> section</span> </p> <p> <span class="content">Another</span> <span class="content"> paragraph</span> </p> <h3 class="title"> <span class="content">Title</span> <span class="content"> 2</span> <span class="content"> is</span> <span class="content"> complex</span> </h3> <p> <span class="content">Here</span> <span class="content"> is</span> <span class="content"> some</span> <span class="content"> text</span> </p>
My output XML considers every <h3> as well as all the <p> tags until the next <h3> . I wrote XSL as follows:
<xsl:template match="h3[@class='title']"> ... <xsl:apply-templates select="following-sibling::p[ generate-id(preceding-sibling::h3[1][@class='title'][text()=current()/text()]) = generate-id(current()) ]"/> ... </xsl:template>
The problem is that I am using the text() method to identify h3s that are the same. In the above example, "Title 2 is complex" title text () method returns a space. My thought was to use a method like jQuery.html, which will return me "Title 2 is complex".
Update: this may help clarify. After the conversion, the desired result for the above will look something like this:
<section> <title>Title</title> <p> <content>Some</content> <content> text</content> <content> for</content> <content> this</content> <content> section</content> </p> <p> <content>Another</content> <content> paragraph</content> </p> </section> <section> <title> <content>Title</content> <content> 2</content> <content> is</content> <content> complex</content> </title> <p> <content>Here</content> <content> is</content> <content> some</content> <content> text</content> </p> </section>
Brian source share