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

RE: Name space confusion

Subject: RE: Name space confusion
From: "Lars Huttar" <lars_huttar@xxxxxxx>
Date: Thu, 30 Oct 2003 21:47:38 -0600
xsl name space
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="http://www.w3.org/1999/XSL/Transform"
> xmlns:fo="http://www.w3.org/1999/XSL/Format">
> 
> <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()}" />
  </xsl:template>

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

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

Lars


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.