'XSLT value-of (within template called with param) seems to work or stop working, depending on other children of the node passed as param
I have the following structure(s) in my xml:
<modelData>
<metadata>
<approverDetails instanceId="0">
<userId/>
<userIdNamespace/>
<fullName>James John Johnson<fullName/>
</approverDetails>
<reviewerDetails instanceId="0">
<userId/>
<userIdNamespace/>
<fullName>Johanna Jameson<fullName/>
</reviewerDetails>
</metadata>
</modelData>
and the xslt to go with it:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="userdetailinfo">
<xsl:param name="personDetails" />
<xsl:variable name="fullNameVar">
(<xsl:value-of select="$personDetails/fullName" />)
</xsl:variable>
<xsl:if test="$fullNameVar!= ''">
<xsl:value-of select="$fullNameVar"/>
</xsl:if>
</xsl:template>
<xsl:template match="/">
Report Approver:
<xsl:call-template name="userdetailinfo">
<xsl:with-param name="personDetails" select="/modelData/metadata/approverDetails"/>
</xsl:call-template>
</xsl:template>
</xsl:stylesheet>
This, as expected, produces the following output:
Report Approver: (James John Johnson)
However, when I modify the xml to add a value to the userIdNamespace tag, like so (line 5):
<modelData>
<metadata>
<approverDetails instanceId="0">
<userId/>
<userIdNamespace>johns-user-id-namespace<userIdNamespace/>
<fullName>James John Johnson<fullName/>
</approverDetails>
<reviewerDetails instanceId="0">
<userId/>
<userIdNamespace/>
<fullName>Johanna Jameson<fullName/>
</reviewerDetails>
</metadata>
</modelData>
This should have no influence on the output, I was expecting identical output as before. Instead, I am getting this:
Report Approver: ()
Clearly, I am misunderstanding how XSLT works, but I couldn't find any useful answers anywhere. Anyone care to help me figure out what I am doing wrong?
Solution 1:[1]
The problem was due to wrong closing tags, <closed><closed/> instead of <closed></closed>.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Natalia Zo? |
