RE: [xsl] How do you handle namespace prefixes in attribute values in XSLT?

Subject: RE: [xsl] How do you handle namespace prefixes in attribute values in XSLT?
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Thu, 5 Dec 2002 10:26:35 -0000
The answer is to copy the namespace node from the source document to the
result document.

<xsl:template name="part">
  <xsl:copy-of select="@element"/>
  <xsl:copy-of select="namespace::*[name() = substring-before(@element,
':')]"/>

Or you could simply copy ALL namespace nodes:

  <xsl:copy-of select="namespace::*"/>

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx 

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Matt Seaborn
> Sent: 05 December 2002 08:45
> To: 'XSL-List@xxxxxxxxxxxxxxxxxxxxxx'
> Subject: [xsl] How do you handle namespace prefixes in 
> attribute values in XSLT?
> 
> 
> Taking a wsdl file (only as an example, applies to any 
> namespaces xml file) which looks like this
>  
> <?xml version="1.0"?>
> <definitions name="StockQuote" 
> targetNamespace="http://example.com/stockquote.wsdl";
> xmlns:xsd1="http://example.com/stockquote.xsd";
> ...
> <message name="GetLastTradePriceOutput">
> <part name="body" element="xsd1:TradePrice"/>
> </message>
>  
> and you wish to operate on it using XSLT. If the prefix 
> 'xsd1' is not used in the QName of an element then when 
> operating on the XML the 'xsd1' prefix will be lost unless it 
> is explicitly declared in the XSLT. However as the actual 
> prefix of a namespace is considered irrelevant it cannot be 
> known before being given the XML document to transform. 
> Assuming the namespace and its prefix is not known in advance 
> and therefore not declared in the XSLT the prefix-namespace 
> association will not be present in the destination document 
> which renders the attribute value 'xsd1:TradePrice' incorrect 
> if it is placed in the destination (transformed) docoument.
>  
> How should this be handled, as I cannot see how to either 
> preseve the prefix-namespace declaration or ensure the 
> namespace is declared and change the prefix to a correct 
> value in the attribute in the destination document?
>  
> Matt Seaborn
> Software Engineer
> Categoric Software 
> 
> The leader in business process event management technology 
> 
> +44 (0)1932 590900 tel
> +44 (0)1932 590901 fax
> +44 (0)1932 590907 direct
> http://www.categoric.com <http://www.categoric.com/> 
> 
> 
>  
> 
>  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