Link to home
Start Free TrialLog in
Avatar of dan_neal
dan_nealFlag for United States of America

asked on

Filter XML data using XSLT Parameters

I have a XSLT style sheet that produces a Hierarchal data structure for some reports that I create.  This XSLT is very generic so I can supply any XML file and receive the same structured output.  I need to expand this to provide Filtering of the data.  I have a method of extracting all attributes from the structure and populate a dropdown as well as populating a second dropdown with values contained by the attribute selected in the first list.  I need to be able to supply a filtering XSLT the name of the attribute and the value selected and then filter the XML based on these selections.

Is there a way to filter by matching attribute name to a parameter value AND the attribute value to a second parameter value?
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
that is looking for an element that has an attribute with that particular name and that particular value
There is no such thing as dynamic XPath in XSLT, that is why it needs to be so clumsy
Avatar of dan_neal

ASKER

Thank you.  I'll try this and respond tomorrow.
Tested xpath with static values and it works.
Changed to use parameters and it fails.
In the code attached, the FValue represents the attribute name and FValue1 represents the attribute value.  I've supplied some default values for testing.  Testing of this setup does not return any results.
Ran through debugging in Visual Studio, in the Watch window I added the $FValue and $FValue1.  $FValue 1 does show the value as the default supplied.  $FValue shows {Dimension[0]}.
What am I doing wrong here?

<xsl:param name="FValue" select="RUID" />
	<xsl:param name="FValue1" select="146" />
	<xsl:param name="Page" select="0" />
	<xsl:param name="PageSize" select="1" />

  <xsl:template match="/"> 
	<table width="100%" border="0" cellspacing="0">
		<xsl:for-each select="child::*/*[@*[name()=$FValue][.=$FValue1]]">
			<tr>
				<td>
					<xsl:call-template name="ProcessMethod"/>
				</td>
			</tr>
		</xsl:for-each>
	</table>
  </xsl:template>

Open in new window

The default RUID is not a string but a node, and in that context RUID has no value
you don't see that problem with the other parameters, since numbers are automaically casted to integers, not node names

try this
<xsl:param name="FValue" select="'RUID'" />
note I added a pair of single quotes inside the double quotes, to make this a string
Genius!!
Now when passing these values from an HTML page, just include the single quote should do the trick right?
no, you don't need to pass the single quotes from the HTML.
Most apis will read the parameters passed in as strings, usually not as nodes