how to pass a parameter and use that in my xslt
Asked Answered
M

1

11

i have a xml file and a related xslt file. I am using msxsl.exe and i need to pass a parameter as a command line argument and use that in my xslt file. how can i do that???

command:

msxsl.exe country.xml sheet.xslt -o country_sheet.html p1="india"

how to retrieve the value india in my xslt file?

Mockingbird answered 1/12, 2010 at 9:19 Comment(0)
S
7

try this

<xsl:param name="p1" select="p1"/>

this would be outside any templates, acting somewhat like a global variable

yes then to use the contents of this you could use this inside a template

<xsl:value-of select="$p1"/>
Sibert answered 1/12, 2010 at 9:21 Comment(5)
thank you so much.... after this line can i use $p1 in for-each select="Root/Row[$p1] statements na????????Mockingbird
my xml file contains a line <india>OK</india> so i am passing india as an argument. now i need to check if india==ok then some other lines..Mockingbird
<xsl:value-of select="$p1"/> i got this working. but i want use it in a if statement. <xsl:if test="india='OK'"> i need to change this line so as to include the $p1. As my xml file contains <india>OK</india>Mockingbird
Consider to post a sample of the XML you have, we would really need to see some context to help you with the specific code. You could try <xsl:for-each select="Root/Row[*[local-name() = $p1] = 'OK']">...</xsl:for-each> if you want a for-each to process all Row elements having a child element of the name the parameter p1 has and where the value of that element is 'OK'. If that does not help then please add a sample of your XML input in your question.Epistyle
@Martin Honnen - thank you so much... its working now.. with the same command....Mockingbird

© 2022 - 2024 — McMap. All rights reserved.