[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Can't make template match root element with schema

Subject: Re: Can't make template match root element with schema info
From: omprakash.v@xxxxxxxxxxxxx
Date: Tue, 15 Mar 2005 09:16:18 +0530
xsl template match xmlns
Hi,
      Not all attributes apecified on the Resume element are
schema-related. Only the xmlns:xsi and xsi:schemalocation pertain to schema
whereas
the xmlns attribute says that the elements in your xml document come from
the HR-XML namespace pointing to by "http://ns.hr-xml.org/2004-08-02
In your stylesheet you have
<xsl:template match="Resume">
</xsl:template>

which is looking for a Resume in the default namespace. If your elements
fall in anything other than the default namespace, then they are invisible
to the stylesheet looking for them in the default namespace.

You can get it to work by modifying your template thus:

<xsl:template match="hr:Resume">
</xsl:template>

and adding a prefix 'hr' to the 'Resume' element in your xml as follows:

<Resume xml:lang="EN" xmlns:hr="http://ns.hr-xml.org/2004-08-02">

Also, you would need to add the xmlns:hr namespace to your xslt file as
well as follows:

<xsl:stylesheet version="1.0"   xmlns:xsl
="http://www.w3.org/1999/XSL/Transform"
xmlns:hr="http://ns.hr-xml.org/2004-08-02"
xmlns:xs="http://www.w3.org/2001/XMLSchema" >


This should get the Resume to be matched even with attributes on the Resume
element (:--)

Cheers,
Omprakash.V








<Resume xml:lang="EN" xmlns="http://ns.hr-xml.org/2004-08-02"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ns.hr-xml.org/2004-08-02
http://ns.hr-xml.org/2_3/HR-XML-2_3/SEP/Resume.xsd" >






                                                                                                                      
                    Ken Gentle                                                                                        
                    <j.kenneth.gentl        To:     xsl-list@xxxxxxxxxxxxxxxxxxxxxx                                   
                    e@xxxxxxx>              cc:     (bcc: omprakash.v/Polaris)                                        
                                            Subject:      Can't make template match root element with schema     
                    03/15/2005 08:47        info                                                                      
                    AM                                                                                                
                    Please respond                                                                                    
                    to xsl-list                                                                                       
                                                                                                                      
                                                                                                                      




Greetings, all!

It took me way too long to figure out what the problem is and I can't seem
to find the answer in the FAQ or lists.

I'm using Altova XML-SPY Home Edition, version 2005 release 3.  I also
tried instant Saxon with similar results.

I am trying to create a stylesheet to format an HR-XML Resume XML
document.  Seemed like a good idea at the time...

Given an xml document that looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="resume.xslt"?>
<Resume xml:lang="EN" xmlns="http://ns.hr-xml.org/2004-08-02"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ns.hr-xml.org/2004-08-02
http://ns.hr-xml.org/2_3/HR-XML-2_3/SEP/Resume.xsd" >
   <ResumeId>
     <IdValue>jkg20050310-000</IdValue>
   </ResumeId>
   <StructuredXMLResume>
   </StructuredXMLResume>
   <NonXMLResume>
   </NonXMLResume>
</Resume>
and the stylesheet that looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
 >
   <xsl:output method="xml"
     doctype-system="
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
     doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" indent="yes"
/>
     <xsl:template match="/">
       <xsl:comment>Matched <xsl:value-of
select="name(current())"></xsl:value-of></xsl:comment>
       <xsl:apply-templates />
     </xsl:template>

     <xsl:template match="Resume">
       <xsl:comment>Matched <xsl:value-of
select="name(current())"></xsl:value-of></xsl:comment>
     </xsl:template>
</xsl:stylesheet>
I get the following output:
<?xml version="1.0" encoding="UTF-8"?><!--Matched -->jkg20050310-000
If I remove the schema information from the root tag of the xml document:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="resume.xslt"?>
<Resume>
   <ResumeId>
     <IdValue>jkg20050310-000</IdValue>
   </ResumeId>
   <StructuredXMLResume>
   </StructuredXMLResume>
   <NonXMLResume>
   </NonXMLResume>
</Resume>
I get the following (more or less expected) output:

<?xml version="1.0" encoding="UTF-8"?><!--Matched -->
<!--Matched Resume-->
I must be missing something really basic here as I don't understand why the

schema related attributes of the xml root tag prevent it from matching
'Resume' in the stylesheet.  Why are attributes affecting this at all?

I did try including the HR-XML namespace in the style sheet and using a
qualified XPath expression in the match ( match="hr:Resume") but that made
no difference in the result.

Thanks in advance!

         Ken Gentle






This e-Mail may contain proprietary and confidential information and is sent for the intended recipient(s) only. 
If by an addressing or transmission error this mail has been misdirected to you, you are requested to delete this mail immediately.
You are also hereby notified that any use, any form of reproduction, dissemination, copying, disclosure, modification,
distribution and/or publication of this e-mail message, contents or its attachment other than by its intended recipient/s is strictly prohibited.

Visit Us at http://www.polaris.co.in

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.