 |
| 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 19th, 2006, 05:59 PM
|
|
Registered User
|
|
Join Date: Jun 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
my stylesheet is ignoring nodes
Hi all:
Input XML:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xt="http://www.jclark.com/xt"
xmlns:common="http://exslt.org/common" xmlns:xalan="http://xml.apache.org/xalan" width="100%"
height="100%">
<defs></defs>
</svg>
XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/2000/svg">
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="svg">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="defs">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="g">
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
But it's ignoring everything after "/" it never goes onto svg, therefore never goes into defs...etc.
any ideas? thanks.
|
|

June 20th, 2006, 02:02 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
Your template matches nodes with local name "svg" in no namespace, you want to match nodes with local name "svg" in namespace http://www.w3.org/2000/svg. Making this the default namespace doesn't work, you need to use an explicit prefix. Search for "XSLT default namespace" for plenty of information on this pitfall.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

June 20th, 2006, 12:53 PM
|
|
Registered User
|
|
Join Date: Jun 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
So now, everyTime I need to refer to svg in my xslt i need to specify the namespace? or maybe i did not understand what you were trying to explain me. Also, I have removed this line from my input document and it seems to work...any ideas? thanks.
<!DOCTYPE svg
PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
|

June 21st, 2006, 02:55 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
Yes, in XSLT 1.0, to refer to an element in a namespace you must use a prefix that is bound to that namespace. In XSLT 2.0 you can use the xpath-default-namespace attribute on the xsl:stylesheet element.
Removing the DOCTYPE declaration has the effect of removing the default namespace declaration, which puts the svg elements in the null namespace.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

June 22nd, 2006, 05:20 PM
|
|
Registered User
|
|
Join Date: Jun 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
How would I refer to element b?
<svg>
<a>
<b>
</b>
</a>
</svg>
I tried svg:a:b but didnt work.
|
|

June 23rd, 2006, 01:59 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
You need to read a basic XSLT tutorial, particularly on XPath, a few seconds searching would have shown that paths are broken down into steps separted by /. So you need:
.
If the document uses namespaced elements then you'll have to apply the rules stated by Dr. Kay previously.
This is a good resource for these sorts of questions:
http://www.dpawson.co.uk/xsl/sect2/sect21.html
--
Joe ( Microsoft MVP - XML)
|
|

June 23rd, 2006, 10:08 AM
|
|
Authorized User
|
|
Join Date: Jun 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Also, for basic tutorials, this one is nice (though maybe a little out of date?):
http://www.zvon.org/xxl/XSLTutorial/...mple1_ch1.html
Just keep hitting next when you are done with a lesson:) I helped me a lot.
|
|

June 30th, 2006, 03:46 PM
|
|
Registered User
|
|
Join Date: Jun 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you so much for your help. I tried a/b/c but didnt work, what it did work tho was a:c or a:b any ideas why?
|
|

June 30th, 2006, 09:17 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
I think it was explained earlier in the thread that if your elements are in a namespace then to select them in XPath you need to use a namespace prefix.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|
 |