Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 12th, 2007, 05:49 AM
Authorized User
 
Join Date: Jul 2006
Location: Valencia, Valencia, Spain.
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default template match doesnt match the required node

Hello all,

I'm having problems when matching the nodes of an xml file.I think there is a problem with namespaces but I cant figure out which one.Ive already read the link http://www.dpawson.co.uk/xsl/sect2/N...tml#d7563e1012 but it didnt help me in my specific problem.

XSL version 2.0

Processor:Saxon 8

XML input:

<?xml version="1.0" encoding="UTF-8"?>
<d2LogicalModel xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://datex2.eu/schema/1_0/1_0" modelBaseVersion="1.0" xsi:schemaLocation="http://datex2.eu/schema/1_0/1_0 C:\DOCUME~1\totres\Escritorio\d1d2transf\DATEXI~1\ DATEXIISchema_1_0_1_0\DATEXIISchema_1_0_1_0.xsd">
    <exchange>
        <supplierIdentification>
            <country>es</country>
            <nationalIdentifier>es001</nationalIdentifier>
        </supplierIdentification>
    </exchange>
    <payloadPublication xsi:type="SituationPublication" lang="es">
        <publicationTime>2007-02-21T09:32:00+01:00</publicationTime>
        <publicationCreator>
            <country>es</country>
            <nationalIdentifier>es001</nationalIdentifier>
        </publicationCreator>
        <situation id="GUID254746">
            <headerInformation>
                <confidentiality>noRestriction</confidentiality>
                <informationStatus>real</informationStatus>
            </headerInformation>
            <situationRecord xsi:type="Activities" id="GUID254746_3O">
                <situationRecordCreationTime>2006-04-04T12:16:00+01:00</situationRecordCreationTime>
                <situationRecordVersion>4</situationRecordVersion>
                <situationRecordVersionTime>2006-04-04T12:16:00+01:00</situationRecordVersionTime>
                <situationRecordFirstSupplierVersionTime>2006-04-04T12:16:00+01:00</situationRecordFirstSupplierVersionTime>
                <probabilityOfOccurrence>certain</probabilityOfOccurrence>
                <validity>
                    <validityStatus>active</validityStatus>
                    <validityTimeSpecification>
                        <overallStartTime>2006-10-17T14:00:00+02:00</overallStartTime>
                        <overallEndTime>2006-10-17T16:00:00+02:00</overallEndTime>
                    </validityTimeSpecification>
                </validity>
                <groupOfLocations>
                    <locationContainedInGroup xsi:type="Linear">
                        <alertCLinear xsi:type="AlertCMethod4Linear">
                            <alertCLocationCountryCode>E</alertCLocationCountryCode>
                            <alertCLocationTableNumber>17</alertCLocationTableNumber>
                            <alertCLocationTableVersion>2.0</alertCLocationTableVersion>
                            <alertCDirection>
                                <alertCDirectionCoded>both</alertCDirectionCoded>
                            </alertCDirection>
                            <alertCMethod4PrimaryPointLocation>
                                <alertCLocation>
                                    <specificLocation>61602</specificLocation>
                                </alertCLocation>
                                <offsetDistance>
                                    <offsetDistance>2099</offsetDistance>
                                </offsetDistance>
                            </alertCMethod4PrimaryPointLocation>
                            <alertCMethod4SecondaryPointLocation>
                                <alertCLocation>
                                    <specificLocation>61608</specificLocation>
                                </alertCLocation>
                                <offsetDistance>
                                    <offsetDistance>2099</offsetDistance>
                                </offsetDistance>
                            </alertCMethod4SecondaryPointLocation>
                        </alertCLinear>
                    </locationContainedInGroup>
                </groupOfLocations>
                <authorityOperationType>policeCheckPoint</authorityOperationType>
            </situationRecord>
        </situation>
    </payloadPublication>
</d2LogicalModel>


XSL:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" >
    <xsl:param name="filtro"/>
    <!--
    Template Principal
    -->
    <xsl:template match="/">
        <xsl:apply-templates select="d2LogicalModel"/>

    </xsl:template>
    <!--
    Template
    -->
    <xsl:template match="d2LogicalModel">

        <xsl:copy>
            <xsl:copy-of select="@*"/>

            <xsl:apply-templates select="exchange"/>
            <xsl:apply-templates select="payloadPublication"/>
        </xsl:copy>
    </xsl:template>
    <!--
    Template
    -->
    <xsl:template match="exchange">
        <xsl:copy>

            <xsl:copy-of select="*"/>
        </xsl:copy>
    </xsl:template>
    <!--
    Template
    -->
    <xsl:template match="payloadPublication">
        <xsl:copy>
            <xsl:copy-of select="child::publicationTime"/>
            <xsl:copy-of select="child::publicationCreator"/>
            <xsl:apply-templates select="situation"/>
        </xsl:copy>
    </xsl:template>
    <!--
    Template
    -->
    <xsl:template match="situation">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:copy-of select="child::headerInformation"/>
            <xsl:if test="count(child::situationRecord[@xsi:type = $filtro]) != 0 ">
                <xsl:apply-templates select="situationRecord"/>
            </xsl:if>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="situationRecord">
        <xsl:if test=" @xsi:type = $filtro ">
            <xsl:copy>
                <xsl:copy-of select="@*"/>
                <xsl:copy-of select="*"/>
            </xsl:copy>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>


Ive been debugging it with xml spy and I found that only the first template is executed, none of the nodes of the xml are matched except the root node('/').

Any ideas?

I will appreciate the help.

Thanks.

Tomi.



Reply With Quote
  #2 (permalink)  
Old March 12th, 2007, 06:07 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

I fail to see how the link you gave didn't help. It clearly shows that you need to declare the http://datex2.eu/schema/1_0/1_0 namespace in your stylesheet so add:
Code:
xmlns:datex="http://datex2.eu/schema/1_0/1_0"
to the xsl:stylesheet element and change your XPath, e.g.
Code:
<xsl:apply-templates select="datex:d2LogicalModel"/>
and
Code:
<xsl:template match="datex:d2LogicalModel">
I chose datex as a prefix but you can pick whatever you want.

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #3 (permalink)  
Old March 12th, 2007, 06:24 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

When you write

<xsl:template match="d2LogicalModel">

you are matching nodes whose name is (local-part="d2LogicalModel, namespace=null). But the node in your source document has (local-part="d2LogicalModel", namespace="http://datex2.eu/schema/1_0/1_0"). To match this node you need to write

<xsl:template match="s:d2LogicalModel">

and add xmlns:s="http://datex2.eu/schema/1_0/1_0" to your xsl:stylesheet. Similarly all the other unqualified element names in match and select attributes need to be prefixed in the same way.

Alternatively since you are using XSLT 2.0 you can add

xpath-default-namespace="http://datex2.eu/schema/1_0/1_0"

to the xsl:stylesheet element.

I'm not sure why the link you reference didn't help you since it describes exactly this problem, and its solution.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Param in template match=" " iceandrews XSLT 2 May 7th, 2008 07:37 AM
value-of inside template match RoeZ XSLT 5 April 17th, 2008 12:09 PM
template m,atch doesnt match Tomi XSLT 1 March 9th, 2007 07:56 AM
import / call / template match Kabe XSLT 3 February 26th, 2004 11:31 AM
help with xsl template match enT XSLT 9 September 24th, 2003 06:21 AM



All times are GMT -4. The time now is 03:14 AM.


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