 |
| XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

June 1st, 2007, 04:27 AM
|
|
Registered User
|
|
Join Date: Jun 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
XSL Param with XPath expressions
Hi !
I'm making a XSL that returns distinct values from a XML Element, but the element is dynamic, so i pass it from the server as a Parameter.
XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" />
<xsl:param name="puff" />
<Element>
<xsl:template match="/">
<xsl:for-each select="//$puff[not(.=preceding::$puff)]">
<value><xsl:value-of select="." /></value>
</xsl:for-each>
</xsl:template>
</Element>
</xsl:stylesheet>
It gives me syntax error when i use the param in the xpath expressions.. any solution? Thanks in advance
|
|

June 1st, 2007, 04:56 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
Variables in XSLT/XPath work like variables in structured programming languages like C or Java - you can use a variable reference anywhere a value is expected. They don't work by textual substitution, like in macro languages. Think of it this way: you can use a variable reference anywhere you might use a number like 12 or a string literal like 'Paris'.
What you want is
"//*[name()=$puff][not(.=preceding::*[name()=$puff])]"
though this will be pretty inefficient on a large document (Muenchian grouping would be much more efficient).
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

June 1st, 2007, 05:13 AM
|
|
Registered User
|
|
Join Date: Jun 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
U're right, it's not efficient, since i use the output for ajax.. and it takes much time to run.. the xml documents are huge! I'll try that Muenchian way, thank you very much.
|
|

June 1st, 2007, 08:19 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
You can do it the way you started with but you need to pass the puff as a node set, not a string. How you do this depends on which XSLT processor you are using. For example in .NET's XslCompiledTransform you use the XlstArgumentList class.
--
Joe ( Microsoft MVP - XML)
|
|

June 1st, 2007, 08:37 AM
|
|
Registered User
|
|
Join Date: Jun 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I am using .NET 1.0, so i use a XslTransform to transform the document, XSLCompiledTransform doesn't exits in 1.0! How would i pass the node set through the parameter? can you guide me the right way? I have low experience using XSLT and XPath. I'm transforming the XML Document this way:
Dim MyXMLDataDocument As XmlDataDocument = New XmlDataDocument(MyDataset)
Dim MyXSLTransform As New Xsl.XslTransform
Dim MyXsltArgumentList As New Xsl.XsltArgumentList
Dim MyXMLResolver As XmlResolver
MyXsltArgumentList.AddParam("Element", "", "Ano")
MyXSLTransform.Load(Server.MapPath(".") & "\Modules\Relatorios\RelatoriosAvancadosPesquisaXM L.xslt")
MyXSLTransform.Transform(MyXMLDataDocument, MyXsltArgumentList, Response.OutputStream, MyXMLResolver)
Thank you in advance
|
|

June 1st, 2007, 08:53 AM
|
|
Registered User
|
|
Join Date: Jun 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ok i already donne it eheh:) always search before replying:)
I've donne it this way:
MyXPathNavigator = MyXMLDataDocument.CreateNavigator()
MyXPathNodeIterator = MyXPathNavigator.Select("Ano")
MyXsltArgumentList.AddParam("Element", "", MyXPathNodeIterator)
It really worked, takes no time to transform the document! Thank you very much!! saved my life=)
|
|

June 1st, 2007, 09:36 AM
|
|
Registered User
|
|
Join Date: Jun 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Seems i made a mistake, it's not really returning anything.. do i use the param the same way? since it's a nodeset? It's not making much sence to me.. anyway, what object do i pass into the xsltransform as input? MyXpathNodeIterator would make sence, since it's him who's getting Select result.. i'm i wrong?
|
|

June 1st, 2007, 11:47 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Try a simple test, create an XSLT with the puff param and one template that matches / and does xsl:copy-of select="$puff". Does that show what you'd expect?
--
Joe ( Microsoft MVP - XML)
|
|
 |