 |
| 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
|
|
|
|

March 25th, 2006, 09:07 AM
|
|
Registered User
|
|
Join Date: Mar 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Problem using xsl:for-each on a exsl:node-set
Hi,
I have some problems looping on a exsl:node-set. I have created a temporary tree that I want to use xpath expressions on.
<xsl:for-each select="exsl:node-set($toXlink)/record/extendedlink/relationship">
<xsl:value-of select="@xlink:href"/>
<xsl:value-of select="@xlink:title"/>
<xsl:value-of select="@xlink:type"/>
</xsl:for-each>
I can't get this working, can anyone help me please, any help would be most appreciated.
Best Regards
Tor Ã
ge Ballo
NTNU Trondheim, Norway
|
|

March 25th, 2006, 09:10 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Have you mapped the namespace to the xlink prefix?
Show the source XML and your stylesheet.
--
Joe ( Microsoft MVP - XML)
|
|

March 25th, 2006, 09:15 AM
|
|
Registered User
|
|
Join Date: Mar 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Yes mate,
here is the modified source and stylesheet.
Source:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="Itegrert.xsl"?>
<record id="7e5cbc6d6a9b80497b90a0a25c91cd6a" type="Korporasjon" template="Korporasjon110">
<relationship rel="er skaper av" rev="er skapt av" target="Verk" href="8f60eefebf6fe1a4e4ee482583464960"/>
<relationship rel="er skaper av" rev="er skapt av" target="Verk" href="181e54d93678bc4a3e5106a064b8f62c"/>
<relationship rel="er skaper av" rev="er skapt av" target="Verk" href="a85d5366d72bb112a9b3a43bc1bc3f7b"/>
<relationship rel="er skaper av" rev="er skapt av" target="Verk" href="28b61a1c49d62e595d5d0c3d0d5b6cb2"/>
</record>
Stylesheet:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:exsl="urn:schemas-microsoft-com:xslt"
extension-element-prefixes="exsl"
version="2.0">
<xsl:variable name="toXlink">
<record>
<xsl:for-each select="record">
<xsl:variable name="home">http://november.idi.ntnu.no/frbrized/getdoc?doc=<xsl:value-of select="@id"/></xsl:variable>
<xsl:variable name="parentTitle"><xsl:value-of select="datafield/subfield[@type='Navn' and @code='a']"/></xsl:variable>
<extendedlink xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="{$home}" xlink:type="extended" xlink:title="{@id}">
<xsl:if test="relationship[@rel='er skaper av']">
<relationship xlink:type="locator" xlink:href="{$home}" xlink:label="Parent" xlink:title="Er skaper av:" xlink:role="er skaper av"/>
<xsl:for-each select="relationship">
<xsl:if test="@rel='er skaper av'">
<xsl:variable name="href">http://november.idi.ntnu.no/frbrized/getdoc?doc=<xsl:value-of select="@href"/></xsl:variable>
<xsl:variable name="Title"><xsl:value-of select="document($href)//record/datafield/subfield"/></xsl:variable>
<xsl:variable name="Type"><xsl:value-of select="@target"/></xsl:variable>
<xsl:variable name="rel"><xsl:value-of select="@rel"/></xsl:variable>
<relationship xlink:type="locator" xlink:href="{$href}" xlink:label="Child" xlink:title="{$Title}" xlink:content-role="{$Type}" xlink:role="{$rel}"/>
</xsl:if>
</xsl:for-each>
<go xlink:type="arc" xlink:title="er skaper av" xlink:from="Parent" xlink:to="Child"/>
</xsl:if>
</extendedlink>
</xsl:for-each>
</record>
</xsl:variable>
<xsl:template name="toHtml" match="/">
<html>
<head>
<title>Drop Down </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<div id="tooltip" style="position:absolute;visibility:hidden"></div>
<div id="vertnav1">
<ul id="nav">
<xsl:for-each select="exsl:node-set($toXlink)/record/extendedlink/relationship">
[list]
<li>
<a>
<xsl:value-of select=""/>
</a>
</li>
</ul>
</xsl:for-each>
</ul>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Thank you for the respond. I really appreciate it.
Regards
Tor Ã
ge Ballo
NTNU Trondheim, Norway
|
|

March 26th, 2006, 09:57 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
I'm afraid there's not enough information here to see what your are doing wrong. One possibility is that the elements (e.g. "record") are in a namespace.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

March 26th, 2006, 10:05 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
I think Joe probably guessed right. If you move this:
xmlns:xlink="http://www.w3.org/1999/xlink"
to the xsl:stylesheet element, then you will be able to use the xlink prefix anywhere in the stylesheet.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

March 27th, 2006, 03:39 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Can you clarify Michael?
That was my initial thought but the xlink namespace is mapped in the stylesheet element.
I think it might be to do with how the extendedlink elements are constructed.
If the exsl:node-set($toXlink) is displayed using xsl:copy-of then the tree looks correct. I'm missing something but not sure what.
--
Joe ( Microsoft MVP - XML)
|
|

March 27th, 2006, 05:47 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
If I change the stylesheet to say
xmlns:exsl="http://exslt.org/common"
and the contents of the for-each to say
<xsl:for-each select="exsl:node-set($toXlink)/record/extendedlink/relationship">
[list]
<li>
<a>
<xsl:value-of select="@xlink:href"/></href>
<title><xsl:value-of select="@xlink:title"/></title>
<type><xsl:value-of select="@xlink:type"/></type>
</a>
</li>
</ul>
</xsl:for-each>
and then run it under Saxon, then it works fine for me. So it looks like something to do with the MS implementation of the node-set() function - which I can't comment on.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

March 27th, 2006, 10:49 AM
|
|
Registered User
|
|
Join Date: Mar 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi guys, thanks for the answers. Sorry for my late respond, have caught the flu.
I'm pretty new on using XSL and really appreciate all the help.
Joe, how did you solve it with xsl:copy-of? Can't get it working even if I use copy-of. Can you please show me how it will look using the xsl:copy-of?
I'm going to try to install Saxon and see if I can get it working using the Saxon processor.
Thanks for your help, most aprreciated.
Kindly regards
Tor
Tor Ã
ge Ballo
NTNU Trondheim, Norway
|
|

March 27th, 2006, 11:03 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
No, I didn't solve it but if you put xsl:copy of select="exsl:node-set($toXlink)" inside the ul then you can see what the $toLink nodes look like.
I was hoping Michael could clarify what's happening.
What platform and XSL processor are you using?
--
Joe ( Microsoft MVP - XML)
|
|

March 27th, 2006, 11:32 AM
|
|
Registered User
|
|
Join Date: Mar 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I have just installed the new Altova XML Spy it comes with a integrated XSL processor. This is all the info I could find on it from the Altova homepage:
"XMLSpy® 2006 includes a standards-conformant Altova XSLT processor for performing XSLT 1.0 and schema-aware XSLT 2.0 transformations, and it also provides built-in support for the MSXML4 XSLT engine."
I'm trying to install Saxon on a Java platform thou.
Best regards
Tor Ã
ge Ballo
NTNU Trondheim, Norway
|
|
 |