Matthew Rees-George
Usenet Archive
- Joined
- Jul 30, 2003
- Messages
- 2
- Reaction score
- 0
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">
<xsl
utput 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> <xsl
therwise><xsl:copy/></xsl
therwise> </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">
<xsl
<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> <xsl
</xsl:stylesheet>
There must be a more obvious solution? Anyone?