Avatar of dan_neal
dan_neal
Flag 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?
Web Languages and StandardsXML

Avatar of undefined
Last Comment
Gertone (Geert Bormans)

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Gertone (Geert Bormans)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Gertone (Geert Bormans)

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
dan_neal

ASKER
Thank you.  I'll try this and respond tomorrow.
dan_neal

ASKER
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

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Gertone (Geert Bormans)

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
dan_neal

ASKER
Genius!!
Now when passing these values from an HTML page, just include the single quote should do the trick right?
Gertone (Geert Bormans)

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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.