I am using XSLT to select and loop through objects with a certain parentID, this is working fine. What I then need to do is check the ID of each selected element of the XML against a value.
Here is my code:
XSL:
<xsl:for-each select="categories/category[@parentId='1333']">
<xsl:choose>
<xsl:when test="id='1349'">Yes</xsl:when>
<xsl:otherwise>No</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
Here is an example XML block:
<categories>
<category !!!!THIS IS THE ID I WANT!!!!! id="1348" parentId="1333">
<name>Name</name>
<description>Desc</description>
<path>/test/test/testing</path>
<category id="1349" parentId="1333">
<name>Name</name>
<description>Desc</description>
<path>/test/test/testing</path>
</category>
<category id="1352" parentId="1333">
<name>Name</name>
<description>Desc</description>
<path>/test/test/testing</path>
</category>
<category id="1370" parentId="1333">
<name>Name</name>
<description>Desc</description>
<path>/test/test/testing</path>
</category>
</categories>
I think it’s simply that you’re not checking for the attribute correctly.
Change…
To (note the extra
@which means it’s an attribute name rather than an element name)…