Cannot apply-templates to child nodes when the context item
Posted: Mon Mar 14, 2011 9:03 pm
Hello,
I'm trying to understand regexes and variables.
I have an xml file:
and an xslt including:
I want the output to be:
ie the class attribute is included when in the form wwdddddd but empty otherwise.
My xslt is producing:
But I can't get the addrLine2 "some text 1" etc to output. If I try
<addrLine2 class="{$classValue}"><xsl:apply-templates/></addrLine2>
I just get "Cannot apply-templates to child nodes when the context item is an atomic value".
Any help with this regex or variable (or whatever else it should be!) would be appreciated!
Thanks,
N
I'm trying to understand regexes and variables.
I have an xml file:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<addresses>
<address>
<addrLine2 class="sh12345678">some text 1</addrLine2>
<addrLine2 class="history">some text 2</addrLine2>
<addrLine2 class="sh">some text 3</addrLine2>
<addrLine2 class="12345678">some text 4</addrLine2>
</address>
</addresses>
Code: Select all
<xsl:template match="addrLine2">
<xsl:variable name="classValue" select="@class"/>
<xsl:analyze-string select="$classValue"
regex="[a-zA-Z]{{2}}[0-9]+">
<xsl:matching-substring>
<addrLine2 class="{$classValue}"></addrLine2>
</xsl:matching-substring>
<xsl:non-matching-substring>
<addrLine2 class=""></addrLine2>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
Code: Select all
<addresses>
<address>
<addrLine2 class="sh12345678">some text 1</addrLine2>
<addrLine2 class="">some text 2</addrLine2>
<addrLine2 class="">some text 3</addrLine2>
<addrLine2 class="">Lsome text 4</addrLine2>
</address>
</addresses>
My xslt is producing:
Code: Select all
<addresses>
<address>
<addrLine2 class="sh12345678"/>
<addrLine2 class=""/>
<addrLine2 class=""/>
<addrLine2 class=""/>
</address>
</addresses>
<addrLine2 class="{$classValue}"><xsl:apply-templates/></addrLine2>
I just get "Cannot apply-templates to child nodes when the context item is an atomic value".
Any help with this regex or variable (or whatever else it should be!) would be appreciated!
Thanks,
N