Dumb XSL question
Sep. 21st, 2004 12:35 pmFor some reason XSL just won't stick in my brain, so I have to ask my friends list.
If I have a document which contains AAA nodes and I want to transform them to BBB nodes I can do something like:
But suppose I want to replace every AAA immediately followed by a CCC (throwing the CCC away)? Something like
is my guess, but then I'm told "Only child:: and attribute:: axes are allowed in match patterns!"
Anyone got any clues? I'm trying to pretend this isn't just directed at
lozette...
If I have a document which contains AAA nodes and I want to transform them to BBB nodes I can do something like:
<xsl:template match="AAA"> <BBB><xsl:apply-templates/></BBB> </xsl:template>
But suppose I want to replace every AAA immediately followed by a CCC (throwing the CCC away)? Something like
<xsl:template match="AAA/following-sibling::CCC[1]"> <BBB><xsl:apply-templates/></BBB> </xsl:template>
is my guess, but then I'm told "Only child:: and attribute:: axes are allowed in match patterns!"
Anyone got any clues? I'm trying to pretend this isn't just directed at
(no subject)
Date: 2004-09-21 12:11 pm (UTC)xsl:template match="AAA"
xsl:if test="following-sibling::*[1][name() = 'CCC']"
...do something
/
/
Not very elegant, though, and totally untested!!
If that doesn't work or isn't right/convenient let me know.
(no subject)
Date: 2004-09-21 12:17 pm (UTC)Thank you for helping, by the way!
(no subject)
Date: 2004-09-21 12:31 pm (UTC)In that case, maybe:
xsl:template match="AAA"
xsl:if test="following-sibling::*[1][name() = 'CCC']"
...do something
/
/
xsl:template match="CCC"
xsl:if test="not(preceding-sibling::*[1][name() = 'AAA')"
...do something
/
/
Or, you could do it sort of backwards...
<xsl:template match="CCC">
<xsl:choose>
<xsl:when test="preceding-sibling::*[1][name() = AAA">
<xsl:apply-templates select="preceding-sibling::AAA[1]" mode="theOneBefore"/>
</xsl:when>
<xsl:otherwise>
...do what you want to do with all CCCs that don't have a preceding AAA
</xsl:otherwise>
</xsl:template>
<xsl:template match="AAA" mode="theOneBefore">
...do what you want to do with all AAAs that have a CCC after them
</xsl:template>
<xsl:template match="AAA"/>
...empty template to match all other AAAs, assuming you have any. Or you can do something in here if you want to.
Again, no idea if this does exactly what you want cos I'm still a bit fuzzy on the requirement ;-)
(no subject)
Date: 2004-09-21 12:51 pm (UTC)Requirements were a bit fuzzy 'cos the actual situation is a bit stupid and I'm embarrassed...
(no subject)
Date: 2004-09-21 01:41 pm (UTC)