I want to test, within an XSLT document, whether an attribute value of type QName from the input XML is equal to another QName from the XSLT document. I want to evaluate each QName according to its parent document namespace declarations before the comparison.
So, the following XSLT...
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="msxsl"
xmlns:aTest="http://tempuri.org/Test"
>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@* | node()">
<xsl:if test="/@name = 'aTest:a'">Success</xsl:if>
</xsl:template>
</xsl:stylesheet>
...given the following input...
<?xml version="1.0" encoding="utf-8" ?>
<root
xmlns:test="http://tempuri.org/Test"
name="test:a"
></root>
...would produce "Success" (I know why it doesn't as is, but hopefully you see my intention).
You must compare the parts before and after the
:
separately. The namespace prefix before the:
can be translated into the namespace URI by looking it up on the corresponding namespace axis:namespace::*
.document('')/*/namespace::*
.If, for some reason, you cannot invoke the function
document('')
, you can simply write the namespace URI and the local name in the condition:(XSLT 1.0)