How to I break an XML node into 2 using XSLT 1.0
How to I break an XML node into 2 using XSLT 1.0
I have an XML node with a child element that I need to break up into two
Something like this
<node margin="5pt" color="red">with some text and <seperator/> where the element continues</node>
The result should be
<node margin="5pt" color="red">with some text and </node>
<node margin="5pt" color="red">where the element continues</node>
1 Answer
1
The following XSLT 1.0 stylesheet will split up the content and produce separate node
elements with the content of the text()
that are siblings to the seperator
element (which is mis-spelled)
node
text()
seperator
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="yes" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="seperator"/>
<xsl:template match="node/text()[preceding-sibling::seperator or following-sibling::seperator]">
<xsl:element name="name(..)">
<xsl:copy-of select="../@*|."/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Comments
Post a Comment