470,811 Members | 1,124 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,811 developers. It's quick & easy.

Traverse XSL stylesheet


I've created an XSL stylesheet that lets me filter data in an
XMLDocument using a transform.

However, I want the filter to be dynamic based on an attribute.

Should I just do a search replace on it?

Or can I pinpoint a specific part of an XSL using the OM?

Jun 13 '06 #1
5 1474


John Bailo wrote:

I've created an XSL stylesheet that lets me filter data in an
XMLDocument using a transform.

However, I want the filter to be dynamic based on an attribute.

Should I just do a search replace on it?

Or can I pinpoint a specific part of an XSL using the OM?


You should define a global parameter e.g.
<xsl:param name="parameterName" />
in the XSLT stylesheet and then use the API of the XSLT processor to set
that parameter before you run a transformation.
In the stylesheet you use the parameter as
$parameterName
in XPath expressions.

Of course manipulation of an XSLT document is possible if you load the
stylesheet in an XmlDocument but defining and setting parameters is the
preferred way. And XPathDocument in .NET, the preferred data store for
XSLT/XPath is read only.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 13 '06 #2
Martin Honnen wrote:
You should define a global parameter e.g.
<xsl:param name="parameterName" />
in the XSLT stylesheet and then use the API of the XSLT processor to set
that parameter before you run a transformation.


Are you talking about the XslTransform API?

I don't see a member to set a parameter once I've loaded the stylesheet
and prior to running the Transform.

http://msdn2.microsoft.com/en-us/lib...ds(VS.80).aspx

Jun 13 '06 #3

Actually, your idea is perfect.

I find some implementation code here:

http://www.ischool.washington.edu/ta...Parameters.htm

That is working for me well.

Thanks for your help!!!
John Bailo wrote:
Martin Honnen wrote:
You should define a global parameter e.g.
<xsl:param name="parameterName" />
in the XSLT stylesheet and then use the API of the XSLT processor to
set that parameter before you run a transformation.

Are you talking about the XslTransform API?

I don't see a member to set a parameter once I've loaded the stylesheet
and prior to running the Transform.

http://msdn2.microsoft.com/en-us/lib...ds(VS.80).aspx

Jun 13 '06 #4

I want to use a param in a conditional as in:

<xsl:param name="partnumid"></xsl:param>

<xsl:choose>
<xsl:when $partnumid="">
<xsl:apply-templates select="partnum"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="partnum[@id=$partnumid]"/>
</xsl:otherwise>
</xsl:choose>

However, during run time, this exception occurs:

6/14/2006 9:37:20 AM:Search:System.Xml.XmlException: The '$' character,
hexadecimal value 0x24, cannot begin with a name. Line 40, position 15.
So, I can use $partnumid in the select statement (in quotes) but not as
a variable in the when clause.

Is there some other way to express the value of the partnumid?

John Bailo wrote:

Actually, your idea is perfect.

I find some implementation code here:

http://www.ischool.washington.edu/ta...Parameters.htm
That is working for me well.

Thanks for your help!!!
John Bailo wrote:
Martin Honnen wrote:
You should define a global parameter e.g.
<xsl:param name="parameterName" />
in the XSLT stylesheet and then use the API of the XSLT processor to
set that parameter before you run a transformation.


Are you talking about the XslTransform API?

I don't see a member to set a parameter once I've loaded the
stylesheet and prior to running the Transform.

http://msdn2.microsoft.com/en-us/lib...ds(VS.80).aspx

Jun 14 '06 #5


John Bailo wrote:

I want to use a param in a conditional as in:

<xsl:param name="partnumid"></xsl:param>

<xsl:choose>
<xsl:when $partnumid="">


That is not proper XML/XSLT syntax, you probably want
<xsl:when test="$partnumid = ''">
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 14 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by R. Rajesh Jeba Anbiah | last post: by
reply views Thread by Egil Hansen | last post: by
3 posts views Thread by visor7 | last post: by
1 post views Thread by SonOfGrey | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.