XSL Help - variable and node-set problem

Here should go questions about transforming XML with XSLT and FOP.
freshbru
Posts: 3
Joined: Wed May 21, 2008 8:36 am

XSL Help - variable and node-set problem

Post by freshbru »

Please see the code below:

Code: Select all


<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<xsl:output method="html"/>
<xsl:param name="appNumber"/>
<xsl:param name="orgApp"/>
<xsl:variable name="upper">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
<xsl:variable name="lower">abcdefghijklmnopqrstuvwxyz</xsl:variable>
<xsl:template match="/">

...
...

<!-- Search Criteria -->

<xsl:variable name="searchCriteria">
<xsl:choose>
<xsl:when test="string-length($appNumber) > 0">
<name>
<xsl:value-of select="Applications/Application[ApplicationNumber = $appNumber]"/>
</name>
</xsl:when>
<xsl:when test="string-length($orgApp) > 0">
<name>
<xsl:value-of select="Applications/Application[OrganisationApplicant[contains(translate(., $upper, $lower), $orgApp)]]"/>
</name>
</xsl:when>
</xsl:choose>
</xsl:variable>

<xsl:value-of select = "msxsl:node-set($searchCriteria)/name"/>

<xsl:for-each select="msxsl:node-set($searchCriteria)/name">

...
...

</xsl:for-each>

...
...
</xsl:template>
The problem I am having is that when I use the '<xsl:value-of select = "msxsl:node-set...' statement I see a list of the returned values requested. However when I use the '<xsl:for-each select="msxsl:node-set...' statement I get absolutley nothing. I have spent many an hour trying SO MANY different solutions and am completely stuck!! :(

If anyone could provide any insight as to what I need to do to get this working I would be forever in your debt!

Cheers,

Freshbru
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: XSL Help - variable and node-set problem

Post by sorin_ristache »

Hello,

The expression "msxsl:node-set($searchCriteria)/name" returns the same nodeset in the xsl:value-of and the xsl:for-each elements. I think the difference comes from the processing that you do in the xsl:for-each element. Can you post a small XML input sample and a reduced XSLT stylesheet that shows the problem? What is the expected output of the stylesheet?


Regards,
Sorin
freshbru
Posts: 3
Joined: Wed May 21, 2008 8:36 am

Re: XSL Help - variable and node-set problem

Post by freshbru »

Hi Sorin,

Many thanks for your prompt reply :)

I have read up on the node-set function and apparently it returns only the 1st node in the list from the specified XPATH which is not what I'm after.

I am trying to dynamically create an XPATH at runtime which I have read numerous times on many a forum that this is not possible. However I have managed to select which XPATH to use by the use of multiple xsl:choose statements; depending on what parameters are specified. Whilst this is not exactly what I'm after it will have to suffice until I can find a more dynamic approach.

Stricly speaking, it is not possible to build an XPATH in xsl but using scripting it is possible to create an XPATH at runtime!

Using this script it should be possible to do it:

Code: Select all


var doc = new ActiveXObject("MSXML2.DOMDocument")

doc.Load("your xml file.xml")

var root = new ActiveXObject("MSXML2.IXMLDOMNode")

var nodeList = new ActiveXObject("MSXML2.IXMLDOMNodeList")

root = doc.DocumentElement

nodeList = root.SelectNodes("Your XPATH")

doc.Save("temp.xml")
When I get round to implimenting this approach I will post the code here.

Thanks for your time.

Cheers,
Freshbru
Post Reply