Subject: Re: [xsl] Transforming XML doc with namespace From: "Darshan Singh" <darshan@xxxxxxxxxxxxxx> Date: Tue, 27 Feb 2001 20:33:19 -0700 |
Change your XSL to: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:mynamespace="blah.blah.blah" version="1.0" > <xsl:template match="mynamespace:book"> <body> <xsl:value-of select="@category"/><br/> <xsl:value-of select="mynamespace:title"/> </body> </xsl:template> </xsl:stylesheet> Basically, I have made two changes: a.) Added "blah.blah.blah" namespace to <xsl:stylesheet declaration, and b.) XPath expressions prefixed with namespace (see how match and select attribute values are namespace prefixed.) That's the way the XSLT processor works. Darshan http://www.PerfectXML.com ---------- Original Message ---------------------------------- From: Mark Edwards <a-marked@xxxxxxxxxxxxx> Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Date: Tue, 27 Feb 2001 15:42:41 -0800 >My job this week is to perform some XSLT on someone else's XML document. >This should be straight forward, but I've been thrown a curve ball that I >haven't seen mentioned in other documentation. > >My question is: How can I get XSLT to work with this document containing a >namespace? (Let's assume I can't have the source document fixed.) > >I've included a minimal demonstration below including both a source file >that works fine and a source file that demonstrates my problem. > > >STYLESHEET: ><xsl:stylesheet > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > version="1.0"> ><xsl:template match="book"> > <html><body> > <xsl:value-of select="@category"/><br/> > <xsl:value-of select="title"/> > </body></html> ></xsl:template> ></xsl:stylesheet> > > >SOURCE THAT WORKS: ><?xml version="1.0"?> ><books> > <book category="reference"> > <author>Nigel Rees</author> > <title>Sayings of the Century</title> > <price>8.95</price> > </book> ></books> >OUTPUT: <html><body>reference<br>Sayings of the Century</body></html> > > >SOURCE THAT BREAKS: ><?xml version="1.0"?> ><books xmlns="blah.blah.blah"> > <book category="reference"> > <author>Nigel Rees</author> > <title>Sayings of the Century</title> > <price>8.95</price> > </book> ></books> >OUTPUT: <?xml version="1.0" encoding="UTF-16"?>Nigel ReesSayings of the >Century8.95 > > >I don't yet understand why the second source file renders in what seems to >be a ramdom fashon. Maybe I'm misunderstanding the basics of namespaces. > >Thanks for your input. > >-Mark > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Transforming XML doc with nam, Mark Edwards | Thread | [xsl] Question on subtotaling, Parinit Girde |
RE: [xsl] RE:"*NEVER* use for-each", Michael Kay | Date | RE: [xsl] RE:"*NEVER* use for-each", Michael Kay |
Month |