I have a list full of items, each item has a categoryid,
i want to filter the list of items by the categoryid in my xsl code, I can do this if i specify what my category id is, but i wanted to try and make it generic, don't know if that makes sense, but please look at the code below.
I am generating my xml using asp and the FilterValue & FilterLabel nodes will vary depending on different params sent to the asp.
# XML
<Root>
<FilterValue>2</FilterValue>
<FilterLabel>CategoryID</FilterLabel>
<List>
<Item>
<Title>Title 1</Title>
<Value>Value 1</Value>
<CategoryID>2</CategoryID>
</Item>
<Item>
<Title>Title 2</Title>
<Value>Value 2</Value>
<CategoryID>2</CategoryID>
</Item>
<Item>
<Title>Title 3</Title>
<Value>Value 3</Value>
<CategoryID>4</CategoryID>
</Item>
</List>
</Root>
# XSL
<xsl
aram name="FilterLabel"><xsl:value-of select="/Root/FilterLabel"></xsl
aram>
<xsl:for-each select="Root/List/Item">
<br></br>
<!-- this works call the node by name 'CategoryID' -->
<xsl:if test="CategoryID = /Root/FilterValue">
Title: <xsl:value-of select="Title" />, <xsl:value-of select="CategoryID" />
</xsl:if>
<!-- this does not work call the node by variable value -->
<xsl:if test="$FilterLabel = /Root/FilterValue">
Title: <xsl:value-of select="Title" />, <xsl:value-of select="CategoryID" />
</xsl:if>
</xsl:for-each>
I have tried different things such as
if test="node()[$FilterLabel] = /Root/FilterValue"
even calling the template with the filter built in
<xsl:template match="Root/List/Item[CategoryID = /Root/FilterValue]">
once again the above works, but these don't
this throws error
<xsl:template match="Root/List/Item[$FilterLabel = /Root/FilterValue]">
this has strange results
<xsl:template match="Root/List/Item[node()[/Root/FilterLabel = /Root/FilterValue]">
any ideas?
i want to filter the list of items by the categoryid in my xsl code, I can do this if i specify what my category id is, but i wanted to try and make it generic, don't know if that makes sense, but please look at the code below.
I am generating my xml using asp and the FilterValue & FilterLabel nodes will vary depending on different params sent to the asp.
# XML
<Root>
<FilterValue>2</FilterValue>
<FilterLabel>CategoryID</FilterLabel>
<List>
<Item>
<Title>Title 1</Title>
<Value>Value 1</Value>
<CategoryID>2</CategoryID>
</Item>
<Item>
<Title>Title 2</Title>
<Value>Value 2</Value>
<CategoryID>2</CategoryID>
</Item>
<Item>
<Title>Title 3</Title>
<Value>Value 3</Value>
<CategoryID>4</CategoryID>
</Item>
</List>
</Root>
# XSL
<xsl
<xsl:for-each select="Root/List/Item">
<br></br>
<!-- this works call the node by name 'CategoryID' -->
<xsl:if test="CategoryID = /Root/FilterValue">
Title: <xsl:value-of select="Title" />, <xsl:value-of select="CategoryID" />
</xsl:if>
<!-- this does not work call the node by variable value -->
<xsl:if test="$FilterLabel = /Root/FilterValue">
Title: <xsl:value-of select="Title" />, <xsl:value-of select="CategoryID" />
</xsl:if>
</xsl:for-each>
I have tried different things such as
if test="node()[$FilterLabel] = /Root/FilterValue"
even calling the template with the filter built in
<xsl:template match="Root/List/Item[CategoryID = /Root/FilterValue]">
once again the above works, but these don't
this throws error
<xsl:template match="Root/List/Item[$FilterLabel = /Root/FilterValue]">
this has strange results
<xsl:template match="Root/List/Item[node()[/Root/FilterLabel = /Root/FilterValue]">
any ideas?