Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filtering Result with dynamic value?

Status
Not open for further replies.

FhHouse

Programmer
May 28, 2001
16
0
0
US
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:param name=&quot;FilterLabel&quot;><xsl:value-of select=&quot;/Root/FilterLabel&quot;></xsl:param>

<xsl:for-each select=&quot;Root/List/Item&quot;>
<br></br>

<!-- this works call the node by name 'CategoryID' -->
<xsl:if test=&quot;CategoryID = /Root/FilterValue&quot;>
Title: <xsl:value-of select=&quot;Title&quot; />, <xsl:value-of select=&quot;CategoryID&quot; />
</xsl:if>

<!-- this does not work call the node by variable value -->
<xsl:if test=&quot;$FilterLabel = /Root/FilterValue&quot;>
Title: <xsl:value-of select=&quot;Title&quot; />, <xsl:value-of select=&quot;CategoryID&quot; />
</xsl:if>

</xsl:for-each>

I have tried different things such as
if test=&quot;node()[$FilterLabel] = /Root/FilterValue&quot;

even calling the template with the filter built in
<xsl:template match=&quot;Root/List/Item[CategoryID = /Root/FilterValue]&quot;>

once again the above works, but these don't
this throws error
<xsl:template match=&quot;Root/List/Item[$FilterLabel = /Root/FilterValue]&quot;>

this has strange results
<xsl:template match=&quot;Root/List/Item[node()[/Root/FilterLabel = /Root/FilterValue]&quot;>

any ideas?

 
I was able to get it by putting the CategoryID into an attribute of the Item <Item CategoryID=&quot;2&quot;>, since it is the only attribute I can access it without knowing what it is, so this works unless I need to have more than this 1 attribute.

<xsl:template match=&quot;Root/List/Item[@node() = /Root/FilterValue]&quot;>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top