• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

xsl getNext to sort output

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi guys - i'm really down because i cannot find / understand my xsl error and i have to finish my work very very soon

the error message (by using xalan to create from the xml file my html output) is the following:
xslt error: the expression does not evaluate to a node-set

and the code fragement is:


<xsl:template name="getNext">
<xsl aram name="currentKnoten" />
<xsl:for-each select="$currentKnoten"> //error is in this line
</xsl:for-each>
</xsl:template>



ok here is the xml code (simplified of course)


<DATA name="testdata">

<OTHERDATA></OTHERDATA>

<INSTANCE class="Start" name="Example Data">
<ATTRIBUTE name="stuff"></ATTRIBUTE>
</INSTANCE>
<INSTANCE class="OpenData" name="OpenData-44422">
<ATTRIBUTE name="Data">Last Name</ATTRIBUTE>
<ATTRIBUTE name="Comment"/>
</INSTANCE>
<INSTANCE class="OpenData" name="OpenData-44425">
<ATTRIBUTE name="Data">Adress</ATTRIBUTE>
<ATTRIBUTE name="Comment"/>
</INSTANCE>
INSTANCE class="ClosedData" name="ClosedData-44431">
<ATTRIBUTE name="Data">Gender</ATTRIBUTE>
<RECORD name="Choice of Responses">
<ROW>
<ATTRIBUTE name="Response" type="STRING">male</ATTRIBUTE>
</ROW>
<ROW>
<ATTRIBUTE name="Response" type="STRING">female</ATTRIBUTE>
</ROW>
</RECORD>
</INSTANCE>
<INSTANCE class="OpenData" name="OpenData-44459">
<ATTRIBUTE name="Data">First Name</ATTRIBUTE>
<ATTRIBUTE name="Comment"/>
</INSTANCE>

<CONNECTOR class="Sub">
<FROM instance="Example Data" class="Start"/>
<TO instance="OpenData-44459" class="OpenData"/>
</CONNECTOR>
<CONNECTOR class="Sub">
<FROM instance="OpenData-44459" class="OpenData"/>
<TO instance="Open Data-44422" class="OpenData"/>
</CONNECTOR>
... some more connectors .....
</DATA>





so what is the aim..... as u can see there is wrong ordner in the xml

last name
address
gender
first name

but the output should be:
first name
last name
adress
gender

there is one way to get the right order --> you can look on the subsequent part there is a FROM and TO and there u can see how the output should look like.... start is of course start...

now i go back to the origin problem... my main idea is the following xsl code... may u can see here the problem with the node site.. but i think u need the xml file or?

however this is my relevant xsl code:


<xsl:template match="DATA">
<xsl:element name="process">
<xsl:attribute name="name">
<xsl:value-of select="@name" />
</xsl:attribute>
<xsl:apply-templates select="INSTANCE"/>
</xsl:element>
</xsl:template>

<xsl:template match="INSTANCE[@class='Data']">
<xsl:element name="node">
<xsl:attribute name="name">
<xsl:value-of select="@name" />
</xsl:attribute>
<xsl:attribute name="class">
<xsl:value-of select="@class" />
</xsl:attribute>
<xsl:call-template name="copyAttributes" />
<xsl:variable name="nextNodes">
<xsl:value-of select="key('keyGetData', key('keyFrom', @name)/../TO/@instance)" />
</xsl:variable>
<xsl:call-template name="getNext">
<xsl:with-param name="currentNode" select="$nextNodes" />
</xsl:call-template>
</xsl:element>
</xsl:template>

<xsl:template name="getNext">
<xsl aram name="currentNode"/>
<xsl:for-each select="$currentNode">
<xsl:element name="node">
<xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
<xsl:attribute name="class"><xsl:value-of select="@class"/></xsl:attribute>
<xsl:variable name="nextNodes">
<xsl:value-of select="key('keyGetData', key('keyFrom', @name)/../TO/@instance)"/>
</xsl:variable>
<xsl:call-template name="copyAttributes"/>
<xsl:call-template name="getNext">
<xsl:with-param name="currentNode" select="$nextNodes"/>
</xsl:call-template>
</xsl:element>
</xsl:for-each>
</xsl:template>

<xsl:template name="copyAttributes">
<xsl:for-each select="descendant::*">
<xsl:copy>
<xsl:copy-of select="@*|node()"/>
</xsl:copy>
</xsl:for-each>
</xsl:template>

<xsl:template match="@*|node()">
<xsl:apply-templates/>
</xsl:template>


hopefully u understand what i mean....
 
Marshal
Posts: 27536
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The error message is correct.You are putting a string in the variable, not a node-set. <xsl:value-of> takes its parameter -- which in this case was a node set -- and converts it to a string. So don't do that. Just assign the node-set to the variable.
 
michi michaela
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you for your help... now it is working!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic