I am having the following XML:
<?xml version="1.0"?>
<abc:Element1 xmlns:abc="http://..../resources/abc/v2/"
...>
<abc:Element2>
<abc:Element3s>
<abc:Element4 name="name1"
resourceRef="name2"/>
</abc:Element3s>
</abc:Element2>
<abc:Resources>
<abc:Resource xsi:type="abc:Something"
name="name2"/>
</abc:Resources>
</abc:Element1>
… and this XSLT stylesheet:
<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:abc="http://.../resources/abc/v2/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:template match="/">
<checker name="something">
<xsl:for-each select="abc:Element1/abc:Element2/abc:Element3s/abc:Element4">
<xsl:variable name="resource" select="@resourceRef"/>
<xsl:variable name="xsiType"><xsl:value-of select="//abc:Resource[@name=$resource]/@xsi:type"/></xsl:variable>
<xsl:choose>
<xsl:when test="$xsiType='abc:Something'">
...
</xsl:when>
<xsl:otherwise>
...
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</checker>
</xsl:template>
</xsl:stylesheet>
I am using XALAN 2.7.1 with org.apache.xalan.xsltc.trax.TransformerFactoryImpl (also tried with org.apache.xalan.processor.TransformerFactoryImpl -> same result) to transform the XML.
I expect the following line to store abc:Something in variable xsiType.
<xsl:variable name="xsiType"><xsl:value-of select="//abc:Resource[@name=$resource]/@xsi:type"/></xsl:variable>
but unfortunatley only Something (without namespace as prefix) is stored in xsiType. I verified this because
<xsl:when test="$xsiType='abc:Something'">
is not true.
I also transformed the XMl using xsltproc and the resulting XML looks as expected. Therefore, I expect the input XML/XSLT stylesheet to be correct. I assume something is wrong with Xalan and its configuration.
Can anyone help?
Your sample data is not well-formed, so it’s difficult to tell. This is likely to be a namespace issues. Here’s a sanitized version of your input and stylesheet that extracts the data you want:
This will produce: