I am getting duplicate records with the following xml and xsl file. I only want to transform 1 set of the list items. Try not removing anything from the xsl part (just add to it), if possible.
<?xml version="1.0" encoding="utf-8" ?>
<data>
<listitems name="Select..." CtrId="Id2"/>
<listitems name="Item A" CtrId="Id2"/>
<listitems name="Item B" CtrId="Id2"/>
<listitems name="Select..." CtrId="Id4"/>
<listitems name="Item A" CtrId="Id4"/>
<listitems name="Item B" CtrId="Id4"/>
<listitems name="Select..." CtrId="Id6"/>
<listitems name="Item C" CtrId="Id6"/>
<listitems name="Item D" CtrId="Id6"/>
</data>
<xsl:template match="data/listitems">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<xsl:value-of select="@name"/>
</body>
</html>
</xsl:template>
Result (Incorrect behavior; Duplicate)
Select… Item A Item B Select… Item A Item B
Desired behavior (Only get 1 set)
Select… Item A Item B
Here’s a relatively simple way of doing this:
Your existing template will actually put in an
htmlelement for everylistitemselement- it seems fairly likely that you probably only want the one.The
<xsl:param>declaration at the top picks the first CtrId in the file, and uses that. You can change that to a literal value withselect="'Id2'"(note the single quotes inside the double quotes), or you can pass a parameter into the stylesheet with the ID you want to pick out.