Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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
 
Old June 19th, 2006, 05:59 PM
Registered User
 
Join Date: Jun 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.

 
Old June 20th, 2006, 02:02 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
 
Old June 20th, 2006, 12:53 PM
Registered User
 
Join Date: Jun 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old June 21st, 2006, 02:55 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
 
Old June 22nd, 2006, 05:20 PM
Registered User
 
Join Date: Jun 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

How would I refer to element b?

<svg>
  <a>
    <b>
    </b>
  </a>
</svg>

I tried svg:a:b but didnt work.

 
Old June 23rd, 2006, 01:59 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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:
Code:
svg/a/b
.
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)
 
Old June 23rd, 2006, 10:08 AM
Authorized User
 
Join Date: Jun 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
 
Old June 30th, 2006, 03:46 PM
Registered User
 
Join Date: Jun 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?

 
Old June 30th, 2006, 09:17 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl:test, but ignoring whitespace mphare XSLT 1 December 5th, 2008 05:23 AM
Ignoring first element using for-each amhicraig XSLT 1 December 4th, 2007 05:41 PM
Ignoring in False clause? gabster XSLT 2 September 7th, 2007 08:29 AM
Ignoring Namespace Pt2 Chamkaur XSLT 1 June 19th, 2006 05:08 AM
Ignoring namespace in source XML Chamkaur XSLT 1 June 16th, 2006 03:29 AM





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