RE: [xsl] Name space confusion

Subject: RE: [xsl] Name space confusion
From: "Lars Huttar" <lars_huttar@xxxxxxx>
Date: Thu, 30 Oct 2003 21:47:38 -0600
Hugh wrote:
> I am wanting to write stylesheets that can be used by xml files from a
> variety of sources
> I have trouble because the name space is not always specified by the
> supplier.  I would like to be able to match on an element of 
> known local
> name, but from a, possibly undefined namespace.
> Sample XSL
> <xsl:stylesheet version="1.0"
> xmlns:xsl="";
> xmlns:fo="";>
> <xsl:template match="/">
> 	<xsl:element name="myNewRoot">
> 		<xsl:for-each select=".//CgPoints">
> 		<xsl:element name="SomeOtherThing">
> 			<xsl:apply-templates select="."/>
> 			</xsl:element>
> 		</xsl:for-each>
> 	</xsl:element>
> </xsl:template>
> <xsl:template match="CgPoints">
> 	<xsl:element name="myFirstLevelChild">
> 	</xsl:element>
> </xsl:template>
> </xsl:stylesheet>

The match pattern is relatively easy; do
  <xsl:template match="*[local-name() = 'CgPoints']">

I'm not sure what you want to do for namespaces in the output...
If you don't need a namespace, you can leave your stylesheet as-is.
If you want to copy the namespace of the input XML, you can do
something like

  <xsl:template match="*[local-name() = 'CgPoints']">
    <xsl:element name="myFirstLevelChild"
       namespace="{namespace-uri()}" />

This will copy the namespace-uri from CgPoints in the input XML.

Hopefully you're not picky about what namespace prefix is used. :-)


 XSL-List info and archive:

Current Thread