M
Matthew Rees-George
I want this example xml:-
<xxx>text before <yyy att="value"/> text in the middle <zzz>ignored
but transformed</zzz> text after</xxx>
To be transformed to this:-
text before value text in the middle 'found a zzz' text after
I.e. the text positions must be preserved, but the element(s) must be
transformed.
I could not find similar problems or solutions on the web or
newsgroups, but I have this solution, which I really, really do not
like:-
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xslutput method="text" indent="yes" encoding="utf-8"/>
<xsl:template match="/">
<xsl:apply-templates select="xxx"/>
</xsl:template>
<xsl:template match="xxx">
<xsl:for-each select="node()">
<xsl:choose>
<xsl:when test="name(.)='yyy'"><xsl:value-of
select="@att"/></xsl:when>
<xsl:when test="name(.)='zzz'">'found a zzz'</xsl:when>
<xsltherwise><xsl:copy/></xsltherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
There must be a more obvious solution? Anyone?
<xxx>text before <yyy att="value"/> text in the middle <zzz>ignored
but transformed</zzz> text after</xxx>
To be transformed to this:-
text before value text in the middle 'found a zzz' text after
I.e. the text positions must be preserved, but the element(s) must be
transformed.
I could not find similar problems or solutions on the web or
newsgroups, but I have this solution, which I really, really do not
like:-
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xslutput method="text" indent="yes" encoding="utf-8"/>
<xsl:template match="/">
<xsl:apply-templates select="xxx"/>
</xsl:template>
<xsl:template match="xxx">
<xsl:for-each select="node()">
<xsl:choose>
<xsl:when test="name(.)='yyy'"><xsl:value-of
select="@att"/></xsl:when>
<xsl:when test="name(.)='zzz'">'found a zzz'</xsl:when>
<xsltherwise><xsl:copy/></xsltherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
There must be a more obvious solution? Anyone?