|
Subject: Re: [xsl] Splitting text nodes - xsl:iterate? From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Wed, 12 Nov 2014 18:18:38 -0000 |
Given an input document looking something like this: <doc> <head><foo/><bar/><baz/></head> <body> <sec> <para>Lorem ipsum dolor sit amet, consectetur adipiscing elit.<box outline="maybe"><para quack="y">Proin id <?foo bar?>bibendum urna, <baz>ut ornare</baz> mi.</para></box></para> <para>Aenean dui risus, <qux>sodales quis leo sit amet, ornare consequat</qux> metus. Ut vel massa congue, egestas nibh et, rutrum odio.</para> </sec> </body> </doc>
(i.e. document markup consisting of arbitrary text and element nodes nested to some unknown depth)
and the requirement for two separate outputs looking like these: <doc> <head><foo/><bar/><baz/></head> <body> <sec> <para><new:start/>Lorem ipsum dolor sit amet, consectetur adipiscing elit.<box outline="maybe"><para quack="y">Proin id <?foo bar?>bibendum urna, <baz>ut ornare</baz> mi.</para></box></para> <para>Aenean dui risus, <qux>sodales quis <new:end/>leo sit amet, ornare consequat</qux> metus. Ut vel massa congue, egestas nibh et, rutrum odio.</para> </sec> </body> </doc>
<sec> <para>Lorem ipsum dolor sit amet, consectetur adipiscing elit.<box outline="maybe"><para quack="y">Proin id <?foo bar?>bibendum urna, <baz>ut ornare</baz> mi.</para></box></para> <para>Aenean dui risus, <qux>sodales quis [...]</qux></para> </sec>
(i.e. a copy of the input, with new:start and new:end elements marking the first 20 words of the document; and separately a copy of those first twenty words, preserving all markup within them and adding ellipses at the end)
<xsl:variable name="d1">
<xsl:apply-templates/>
</xsl:variable><xsl:template match="node()" mode="sep">
<xsl:param name="nodes" tunnel="yes"/>
<xsl:if test=". intersect $nodes">
<xsl:copy>
<xsl:apply-templates select="@* , node()" mode="sep"/>
</xsl:copy>
</xsl:if>
</xsl:template><xsl:template match="new:end" mode="sep"> <xsl:text>[...]</xsl:text> </xsl:template>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* , node()"/>
</xsl:copy>
</xsl:template><xsl:template match="$end-node"> <xsl:value-of select="substring-before(., $end-words)"/> <new:end/> <xsl:value-of select="$end-words"/> </xsl:template>
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Splitting text nodes - xs, David Rudel fwqhgads | Thread | [xsl] Re: How do I properly define , Catherine Wilbur cwi |
| Re: [xsl] For CSV output file - sho, Flanders, Charles E | Date | [xsl] Re: How do I properly define , Catherine Wilbur cwi |
| Month |