[Home] [By Thread] [By Date] [Recent Entries]
At 2008-09-28 12:29 -0400, Syd Bauman wrote:
True, but a key table always contains tree nodes and is indexed by values ... you cannot load up a key table with strings. b) there's gotta be a better way. I would have used analyze-string, as below, except that I haven't got the time right now to figure out how to check for and preserve a value that contains nested parentheses. So the answer below is incomplete. I hope this helps. . . . . . . . . . . . Ken t:\ftemp>type syd.xml <?xml version="1.0" encoding="US-ASCII"?> <tests> <test>name1 (value1) name2 (value2) name3 (value3)</test> <test>name1 (value1)name2 () name3(value3)</test> <test>name1(value1)name2()name3()</test> </tests> t:\ftemp>type syd.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xsd"
version="2.0"><xsl:output method="text"/> <xsl:template match="test">
With: <xsl:value-of select="."/>
<xsl:text>
</xsl:text>
<xsl:analyze-string select="." regex="\s*(\i\c*)\s*\((.*?)\)\s*">
<xsl:matching-substring>
<xsl:choose>
<xsl:when test="regex-group(1)='name-check'">
<!--do something-->
</xsl:when>
<xsl:when test="regex-group(2)='value-check'">
<!--do something-->
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'[Got',regex-group(1),
'with',regex-group(2),']'"/>
<xsl:text>
</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:message>
<xsl:text>Whoops! What happened here: </xsl:text>
<xsl:value-of select="."/>
</xsl:message>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template></xsl:stylesheet> t:\ftemp>xslt2 syd.xml syd.xsl con
t:\ftemp>
|

Cart



