I want to use the @sourcename attribute as follows, as a convenience:
If @sourcename has a point in it, $srcgroup must be assigned before the first point, and the part after the first point must be assigned to $srcword .
Otherwise, $srcgroup should be set to @sourcename , and $srcword should be an empty string.
In both cases, I want to do the same using $srcgroup and $srcword .
I tried this with the following snippet:
<xsl:choose> <xsl:when test="contains(@sourcename, '.')"> <xsl:variable name="srcgroup" select="substring-before(@sourcename, '.')"/> <xsl:variable name="srcword" select="substring-after(@sourcename, '.')" /> </xsl:when> <xsl:otherwise> <xsl:variable name="srcgroup" select="@sourcename" /> <xsl:variable name="srcword" /> </xsl:otherwise> </xsl:choose> <foo group="{$srcgroup}" word="{$srcword}" />
The problem is that I get an error (this is using JAXP in Java):
ERROR: [my xsl file]: line 35: Variable or parameter 'srcgroup' is undefined.' FATAL ERROR: 'Could not compile stylesheet' Exception in thread "main" javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:825)
If I understand this right, I assume that the variables have only the specific case area in the <xsl:choose> block. Is there any way around this? I do not want to repeat the second code twice.
ps I found a workaround:
<xsl:variable name="srcgroup" select="substring-before(concat(@sourcename, '.'), '.')" /> <xsl:variable name="srcword" select="substring-after(@sourcename, '.')" />
but I still want to know how to solve my initial question, for future reference.