From within a template I'm trying to set a variable using a select= which references an absolute path. But when the "root" element specifies an xmlns= namespace, the select fails (returns an empty string). Here's the XSLT:
<?xml version="1.0" ?>
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://foo.bar.com/something"
>
<xsl:output method="xml" indent="yes" encoding="windows-1252" />
<xsl:template match="@*|*">
<xsl:copy>
<xsl:apply-templates select="@*" />
<xsl:apply-templates select="*" />
</xsl:copy>
</xsl:template>
<xsl:template match="*[@Mark]">
<xsl:variable name="the_val" select="/Top/Wanted/@Val"/>
<NewNode NewVal="{$the_val}" />
</xsl:template>
</xsl:transform>
And here is the input XML:
<?xml version="1.0" encoding="windows-1252"?>
<Top xmlns="http://foo.bar.com/something">
<Wanted Val='get this' />
<FromHere Mark='X'/>
</Top>
And this is the result:
<?xml version="1.0" encoding="windows-1252"?>
<Top xmlns="http://foo.bar.com/something">
<Wanted Val="get this"></Wanted>
<NewNode NewVal="" />
</Top>
When I remove the xmlns= from both the XSLT and XML, it works. I can't do that in practice, because I have no control over the XML that is being sent to me -- I can only change the XSLT. Also, in reality the XML documents are more complex with deep, multi-level hierarchy, which is why I need to use an absolute path.
TIA for any help.