Subject: Re: [xsl] Global namespace prefixes (Corrected Examples) From: David Carlisle <davidc@xxxxxxxxx> Date: Thu, 13 Nov 2008 23:35:20 GMT |
> And it works. Output: > > <?xml version="1.0" encoding="UTF-8"?> > <output xmlns:dap="http://xml.opendap.org/ns/DAP/3.2#"> > <ns0:Conventions xmlns:ns0="http://base.document/att#">CF-1.0</ I'm surprised by those prefixes. An XSLT 1 processor is given a lot of freedom to change prefixes at will, but most do not do so unless forced to do so to avoid a namespace clash. saxon6 (the old xslt 1 version of saxon) produces $ saxon mns.xml mns.xsl <?xml version="1.0" encoding="UTF-8"?> <output xmlns:dap="http://xml.opendap.org/ns/DAP/3.2#"> <Conventions xmlns="http://base.document/att#">CF-1.0</Conventions> <logname xmlns="http://base.document/att#">olson</logname> <host xmlns="http://base.document/att#">bb0001en</host> </output> In XSLT2 the system wuld have to generate unprefixed names in this context and saxon9 produes the same result: $ saxon9 mns.xml mns.xsl Warning: at xsl:stylesheet on line 5 column 9 of mns.xsl: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor <?xml version="1.0" encoding="UTF-8"?> <output xmlns:dap="http://xml.opendap.org/ns/DAP/3.2#"> <Conventions xmlns="http://base.document/att#">CF-1.0</Conventions> <logname xmlns="http://base.document/att#">olson</logname> <host xmlns="http://base.document/att#">bb0001en</host> </output> Note that while no prefixes are generated the namespace declaration does appear multiple times as there is no parent element with the same namespace. If the element <output> was placed in the namespace instead of no-namespace then the namespace would only need to be declared once. If I change the stylesheet to <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dap="http://xml.opendap.org/ns/DAP/3.2#" > <xsl:output method='xml' version='1.0' encoding='UTF-8' indent='yes'/> <xsl:template match="dap:Dataset" > <xsl:element name="output" namespace="{/dap:Dataset/@base}/att#"> <xsl:apply-templates /> </xsl:element> </xsl:template> <xsl:template match="dap:Attribute" > <xsl:element name="{@name}" namespace="{/dap:Dataset/@base}/att#"><xsl:value-of select="." /></xsl:element> </xsl:template> </xsl:stylesheet> I get $ saxon mns.xml mns.xsl <?xml version="1.0" encoding="UTF-8"?> <output xmlns="http://base.document/att#"> <Conventions>CF-1.0</Conventions> <logname>olson</logname> <host>bb0001en</host> </output> David ________________________________________________________________________ The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom. This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. ________________________________________________________________________
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Global namespace prefixes, Michael Kay | Thread | Re: [xsl] Global namespace prefixes, Nathan Potter |
RE: [xsl] Global namespace prefixes, Michael Kay | Date | Re: [xsl] Global namespace prefixes, Nathan Potter |
Month |