(XSLT) Check if element node exists
(XSLT) Check if element node exists
(OP)
Hi,
In an XSLT template, I'm trying to import an element from an external XML file, and if the element does not exist in the external file, then I add it myself.
What I did was a copy-of(xpath to externale doc), and that works fine. However, after that I do a test to check whether the said element exitsts or not (xsl if "count(element)=0").
And there's the problem, the if seems to always evaluate to true and then I have duplicate elements when the copy-of actually returns something.
Here's the troubling code (XSLT 1.0) :
I'm sure I'm missing something here...
Any suggestion would be more than welcome.
Thanks a lot.
MFR
In an XSLT template, I'm trying to import an element from an external XML file, and if the element does not exist in the external file, then I add it myself.
What I did was a copy-of(xpath to externale doc), and that works fine. However, after that I do a test to check whether the said element exitsts or not (xsl if "count(element)=0").
And there's the problem, the if seems to always evaluate to true and then I have duplicate elements when the copy-of actually returns something.
Here's the troubling code (XSLT 1.0) :
CODE
<xsl:copy-of select="document('TestDoc.xml')//form[@templateref=$formname]/item[@templateref=$itemname]/data"/>
<xsl:if test="count(data)=0">
<xsl:element name="data">
<xsl:element name="possiblevalues00"/>
<xsl:element name="uservalues00"/>
</xsl:element>
</xsl:if>
<xsl:if test="count(data)=0">
<xsl:element name="data">
<xsl:element name="possiblevalues00"/>
<xsl:element name="uservalues00"/>
</xsl:element>
</xsl:if>
I'm sure I'm missing something here...
Any suggestion would be more than welcome.
Thanks a lot.
MFR

Talk To Other Members
RE: (XSLT) Check if element node exists
<xsl:if test="$nset_ext">
<xsl:copy-of select="$nset_ext" />
</xsl:if>
<xsl:if test="not($nset_ext)">
<xsl:element name="data">
<xsl:element name="possiblevalues00"/>
<xsl:element name="uservalues00"/>
</xsl:element>
</xsl:if>
RE: (XSLT) Check if element node exists