Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
All Other Wrox Books Do you have a question about a Wrox book that isn't listed anywhere on p2p.wrox.com or where the forum is locked? Here's a forum to post questions about any other Wrox book so that other readers or one of the authors can help you with your questions. IF YOU ARE LOOKING FOR CODE DO NOT ASK "Where can I find the code for this book?" That question is answered here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the All Other Wrox Books 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
  #1 (permalink)  
Old September 24th, 2004, 07:46 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default resolve-Qname in XPath 2.0 by M. Kay

Dear Michael

In the functions glossary (page 404) I'm trying to understand the example:
Code:
<doc xmlns:one="one.uri" xmlns="default.uri">
  <chap xmlns="" att-one="text">
    <data-one>one:value</data-one>
    <data-two>value</data-two>
  </chap>
</doc>
variables:
$chap /doc/chap
$data1 /doc/chap/data-one
$data2 /doc/chap/data-two

You then show
Code:
resolve-QName(Schap/@att-one, $chap)
as returning (in Clark notation)
Code:
{default.uri}text
.
I don't follow, isn't there no default namespace on $chap so the function returns
Code:
{}text
, or have I misunderstood?

--

Joe
__________________
Joe
http://joe.fawcett.name/
  #2 (permalink)  
Old September 24th, 2004, 12:33 PM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I'm even more lost now, I tried the following stylesheet:
Code:
<xsl:stylesheet
   version="2.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:one="one.uri"
   xmlns:def="default.uri">

<xsl:output method="text" indent="yes"/>

<xsl:variable name="doc" select="/def:doc"/>
<xsl:variable name="chap" select="/def:doc/chap"/>
<xsl:variable name="data1" select="/def:doc/chap/data-one"/>
<xsl:variable name="data2" select="/def:doc/chap/data-two"/>

<xsl:template match="/">
  <xsl:variable name="res0" select="resolve-QName($chap/@att-one, $doc)"/>
  {<xsl:value-of select="namespace-uri-from-QName($res0)"/>}<xsl:value-of select="local-name-from-QName($res0)"/><xsl:text>#xa;</xsl:text>
  <xsl:variable name="res1" select="resolve-QName($chap/@att-one, $chap)"/>
  {<xsl:value-of select="namespace-uri-from-QName($res1)"/>}<xsl:value-of select="local-name-from-QName($res1)"/><xsl:text>#xa;</xsl:text>
  <xsl:variable name="res2" select="resolve-QName(string($data1), $data1)"/> 
  {<xsl:value-of select="namespace-uri-from-QName($res2)"/>}<xsl:value-of select="local-name-from-QName($res2)"/><xsl:text>#xa;</xsl:text>
  <xsl:variable name="res3" select="resolve-QName(string($data2), $data2)"/>
  {<xsl:value-of select="namespace-uri-from-QName($res3)"/>}<xsl:value-of select="local-name-from-QName($res3)"/><xsl:text>#xa;</xsl:text>
</xsl:template>
</xsl:stylesheet>
against the doc shown above. I get:
  {}text

  {}text

  {one.uri}value

  {}value
then I tried adding xpath-default-namespace="default-uri" and removing the def: prefix from the variables declarations and the stylesheet namespace declaration. This led to an error indicating that $chap/@att-one was an empty sequence. I presume this is something to do with the default namespace being undeclared. The full stylesheet:
Code:
<xsl:stylesheet
   version="2.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:one="one.uri"
   xpath-default-namespace="default.uri">

<xsl:output method="text" indent="yes"/>

<xsl:variable name="doc" select="/doc"/>
<xsl:variable name="chap" select="/doc/chap"/>
<xsl:variable name="data1" select="/doc/chap/data-one"/>
<xsl:variable name="data2" select="/doc/chap/data-two"/>

<xsl:template match="/">
  <xsl:variable name="res0" select="resolve-QName($chap/@att-one, $doc)"/>
  {<xsl:value-of select="namespace-uri-from-QName($res0)"/>}<xsl:value-of select="local-name-from-QName($res0)"/><xsl:text>#xa;</xsl:text>
  <xsl:variable name="res1" select="resolve-QName($chap/@att-one, $chap)"/>
  {<xsl:value-of select="namespace-uri-from-QName($res1)"/>}<xsl:value-of select="local-name-from-QName($res1)"/><xsl:text>#xa;</xsl:text>
  <xsl:variable name="res2" select="resolve-QName(string($data1), $data1)"/> 
  {<xsl:value-of select="namespace-uri-from-QName($res2)"/>}<xsl:value-of select="local-name-from-QName($res2)"/><xsl:text>#xa;</xsl:text>
  <xsl:variable name="res3" select="resolve-QName(string($data2), $data2)"/>
  {<xsl:value-of select="namespace-uri-from-QName($res3)"/>}<xsl:value-of select="local-name-from-QName($res3)"/><xsl:text>#xa;</xsl:text>
</xsl:template>

</xsl:stylesheet>
I'm using Saxon 8 basic.

Any help appreciated.

--

Joe
  #3 (permalink)  
Old September 25th, 2004, 04:19 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Your first comment is correct. The result of the first example should be "{}text".

When you declare a default XPath namespace, the path expressions
select nothing because the /chap is expanded to {default-uri}chap, and there is
no such element (the chap element is in no namespace). However, the latest versions
of the spec say that this is not an error: resolve-QName should return () if the
first argument is (). Saxon needs to be updated.

It also appears that the current Saxon implementation is returning the null namespace
for all unprefixed names, rather than the default namespace. This is incorrect, and
appears to be based on an earlier version of the spec that either defined it this way,
or left it unclear what was intended. (Unprefixed QNames in XSLT content always assume
the null namespace, whereas unprefixed QNames in XML Schema assume the default namespace,
and this function is specified to use the latter interpretation.)

Thanks for the comment.

Generally, if you have a comment on Saxon it's best to send it via the saxon-help list at
Sourceforge; if you find an error in the books, it's best to use the errata form. This time
you seem to have succeeded in doing both at once!



Michael Kay

Michael Kay
http://www.saxonica.com/
  #4 (permalink)  
Old September 25th, 2004, 05:05 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Many thanks Michael, I wasn't sure it was a mistake that's why I asked here :)

Two more points -

I still don't understand why resolve-QName($chap/@att-one, $doc) doesn't resolve 'value' to {one.uri}value when $doc is used for the resolving node as it has one mapped to one.uri.

Following on from where you said
Quote:
quote:When you declare a default XPath namespace, the path expressions
select nothing because the /chap is expanded to {default-uri}chap, and there is
no such element (the chap element is in no namespace).
, does that mean once I have used the xpath-default-namespace I can't select this sort of element (no namespace)?

--

Joe




Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing nodes attribute(Michael Kay help meeee) sumapathy XSLT 4 August 25th, 2007 03:21 AM
How to resolve IDREF in XSL teahouse XSLT 3 September 15th, 2006 01:14 PM
removing name space (qname i think) TylerDerdin XSLT 3 August 23rd, 2006 01:14 PM
need to resolve this.,. razmar78 BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 2 November 23rd, 2004 01:41 PM
resolve-Qname in XPath 2.0 by M. Kay joefawcett XSLT 1 September 26th, 2004 05:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.