Subject: Re: [xsl] Can't make template match root element with schema info From: omprakash.v@xxxxxxxxxxxxx Date: Tue, 15 Mar 2005 09:16:18 +0530 |
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: [xsl] 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Can't make template match roo, Ken Gentle | Thread | Re: [xsl] Can't make template match, Wendell Piez |
[xsl] Can't make template match roo, Ken Gentle | Date | Re: [xsl] Format-Number Function, Jay Bryant |
Month |