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 16th, 2006, 03:21 AM
Authorized User
 
Join Date: May 2006
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default namespace problems in xslt

I have now got almost all of my xslt stylesheet working by changing the namespace, but one of the templates is not working and I dont realy understand what I am doing wrong. A simplified version:

XML is
-------------------------------------------------
<article xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://docbook.org/ns/docbook
docbook.xsd">
    <title/>
    <section>
    <title>section title</title>
    <simplesect>
        <para>section paragraph</para>
        <example>
    <title>example title</title>
    <para>example para</para>
        </example>
    </simplesect>

    </section>

</article>
----------------------------------------------

XSLT is:
----------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns="http://docbook.org/ns/docbook">


<xsl:template match="/">

<html>
    <head>
        <title></title>
    </head>
    <body>

    <xsl:apply-templates />


    </body>
</html>


</xsl:template>

<xsl:template match="ns:simplesect">

<xsl:apply-templates select="ns:para"/>

<blockquote><h4><xsl:apply-templates select="ns:example/title/text()"/></h4>

 <xsl:apply-templates select="ns:example/para/text()"/></blockquote>

</xsl:template>

<xsl:template match="ns:para">
<p><xsl:apply-templates select="text()"/></p>
</xsl:template>

</xsl:stylesheet>

------------------------------------------------

This is a simplified version of my acutal problem: I have to access the "example" element in this way via the "simplesect" element otherwise the rest of my stylesheet does not work in the more complex version.

What Am I doing wrong?



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

This: ns:example/title/text()

should be: ns:example/ns:title/text()


Similarly in the next line: ns:example/ns:para/text()

Though I'm not sure why you have a template matching ns:para elements and then bypass the element when doing apply-templates, going straight to the text nodes instead.


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old June 16th, 2006, 09:59 AM
Authorized User
 
Join Date: May 2006
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, thats working now.

Quote:
quote:Though I'm not sure why you have a template matching ns:para elements and then bypass the element when doing apply-templates, going straight to the text nodes instead.

In the full working version, the <example> element only gets processed if its atribute has a certain value. And the template that processes the text node of the <para> element directly makes sure that the contents of all <para> elements, not just those in <example> are between <p> tags.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Namespace problems riffla XSLT 1 April 10th, 2008 06:18 PM
Namespace trouble when nesting xslt-s dirkvdb XSLT 1 July 26th, 2007 09:02 AM
Default Namespace - XSLT 1.0 Geierwally XSLT 2 July 9th, 2007 11:08 AM
dynamic xslt -> xslt creation namespace problem jkmyoung XSLT 2 July 15th, 2006 12:42 AM





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