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 October 25th, 2006, 04:23 PM
Registered User
 
Join Date: Oct 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Templates Won't Apply

I have a fairly simple XML file and simple stylesheet. The problem is that the processors I have used seem to ignore the templates I have used even when there is a clear match.

Here is the XML:

<FullDataSet xmlns="SMschema">
  <TransactionInfo>
    <TransactionType>CMSGenerate</TransactionType> <ExternalSystemId>aeaee47d-858b-4843-a0e3-1fa0f000d03b</ExternalSystemId>
  </TransactionInfo>
  <Card CardId="11">
    <ManufacturerCardId />
    <IssueDate>20061024</IssueDate>
    <SerialNumber>0000000011</SerialNumber>
    <DeptCode>001300</DeptCode>
    <AgencyCode>1300</AgencyCode>
    <FacilityCode>00003</FacilityCode>
    <DeptName>Deptartment of Commerce</DeptName>
    <AgencyName>Deptartment of Commerce</AgencyName>
    <FacilityName>All Badging / NIST</FacilityName>
    </Card>
</FullDataSet>

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

Here is the relevant part of the XSLT:

<xsl:template match="/*">
        <xsl:element name="CardRequest">
            <xsl:apply-templates />
        </xsl:element>
    </xsl:template>

    <xsl:template match="//Card" priority="101">
        <xsl:element name="Parameters">
            <xsl:element name="SourceID"><xsl:value-of select="@CardId"/></xsl:element>
        </xsl:element>
        <xsl:element name="Agency">SOMETHING</xsl:element>
    </xsl:template>

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

Notice that Card is the second child of the root, and I match on "//Card" anyway. So it shouldn't matter what the context node is. Still that template never gets called with the <apply-templates> call. I have tried moving everything up to the main template and different but equivalent XPath expressions. Nothing works.

Any help or insight is appreciated.

Thanks.
 
Old October 25th, 2006, 08:00 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

I tested your code and it produced the following:

<CardRequest>CMSGenerateaeaee47d-858b-4843-a0e3-1fa0f000d03b200610240000000011001300130000003Depta rtment of CommerceDeptartment of CommerceAll Badging / NIST</CardRequest>

What was the desired result?

what processor are you using and what version of XSLT?


 
Old October 25th, 2006, 08:40 PM
Registered User
 
Join Date: Oct 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, for the XSLT snippet above, the desired output would be the following:

<CardRequest>
  <Parameters>
    <SourceID>11</SourceID>
  </Parameters>
  <Agency>Something</Agency>
</CardRequest>

To answer your questions, I am using XSLT 1.0, and I have found the same results using XML Spy and Saxon.

Thanks for taking the time to look into this.
 
Old October 26th, 2006, 02:17 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Suggest you read the first post in this forum and see the link about namespaces. Basically you don't have an element named Card in your XML.

--

Joe (Microsoft MVP - XML)
 
Old October 26th, 2006, 03:55 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Your document is in a namespace. The element name is not "Card" it is "x:Card" where the prefix "x" represents the namespace "SMschema". You need to use a prefix bound to this namespace in your XPath queries and XSLT match patterns.

Google for "FAQ XSLT default namespace".

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old October 26th, 2006, 01:39 PM
Registered User
 
Join Date: Oct 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I can't say that I found any useful references on the topic, but I played around and figured it out. Thank you so much, Joe and Michael, for your help.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Exclude Elements in Apply Templates mail4kaja XSLT 18 November 29th, 2008 12:09 PM
Apply-templates combined with with-param ? Smirre XSLT 6 November 11th, 2008 08:25 AM
apply-templates problem within for-each loop mister_mister XSLT 2 January 22nd, 2007 05:40 PM
Can I 'apply-templates' across multiple XML docume mphare XSLT 1 June 8th, 2006 05:12 PM
xsl:apply-templates on Variable containing xml nexus5 XSLT 9 November 4th, 2004 02:55 PM





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