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

RE: Creating namespace nodes

Subject: RE: Creating namespace nodes
From: <tomas.vanek@xxxxxxxxxxxxx>
Date: Tue, 7 Jun 2005 12:39:02 +0200
creating an jdk endorsed directory
<xsl:template match="h">
  <xsl:param name="namespaces">xxx=http://www.accenture.com/xxx,
test=http://www.accenture.com/some/Test</xsl:param>
  <xsl:copy>
			<xsl:call-template name="add-ns">
				<xsl:with-param name="ns"
select="$namespaces"/>
			</xsl:call-template>
  </xsl:copy>
</xsl:template>

	<!-- === Template: name="add-ns" === -->
	<xsl:template name="add-ns">
		<xsl:param name="ns"/>
		<xsl:if test="$ns">
			<!-- data separation -->
			<xsl:variable name="first"
select="normalize-space( substring-before( $ns, ',' ) )"/>
			<xsl:variable name="actual" select="concat(
substring( $first, 1 div ( string-length( $first ) != 0 ) ), substring(
normalize-space( $ns ), 1 div ( string-length( $first ) = 0 ) ) )"/>
			<xsl:variable name="remaining"
select="normalize-space( substring-after( $ns, ',' ) )"/>

			<!-- action -->
			<xsl:variable name="prefix"
select="substring-before( $actual, '=' )"/>
			<xsl:variable name="uri"
select="substring-after( $actual, '=' )"/>
			<xsl:attribute
name="{concat($prefix,':dummy-for-xmlns')}" namespace="{$uri}"/>

			<!-- recursion -->
			<xsl:call-template name="add-ns">
				<xsl:with-param name="ns"
select="$remaining"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>

The idea is the same as in your code. I picked it from Schematron....
This didn't work for the default Xalan / Xerces in JDK (1.4.0) because
of a BUG, you have to download the actual version and add to "endorsed"
directory.

tomi


-----Original Message-----
From: Mukul Gandhi [mailto:mukul_gandhi@xxxxxxxxx]
Sent: Tuesday, June 07, 2005 12:21 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  Creating namespace nodes

I am using XSLT 1.0 ;)

"I need to write a identity transform, and add a namespace node to a
particular element in the result tree.."

I have written the following XSLT (1.0) stylesheet so far ..

<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:output method="xml" indent="yes" />

<xsl:template match="node() | @*">
   <xsl:copy>
      <xsl:apply-templates select="node() | @*" />
   </xsl:copy>
</xsl:template>

<xsl:template match="h">
  <xsl:copy>
    <xsl:attribute name="temp"
namespace="http://whatever" />
    <xsl:apply-templates select="node() | @*" />
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>

The input XML is -

<?xml version="1.0"?>
<a id="10">
  <b id="9">
    <c id="8">
      <d id="7">
        <a id="5">
          <h id="6" />
        </a>
      </d>
    </c>
  </b>
</a>

The output produced with the above stylesheet is -

Warning: Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor <?xml
version="1.0" encoding="UTF-8"?> <a id="10">
     <b id="9">
          <c id="8">
               <d id="7">
                    <a id="5">
                         <h temp: id="6"/>

                    </a>
               </d>
          </c>
     </b>
</a>

I am using Saxon 8.4 ..

I desire output -

<?xml version="1.0" encoding="UTF-8"?>
<a id="10">
     <b id="9">
          <c id="8">
               <d id="7">
                    <a id="5">
                         <h
xmlns:temp="http://whatever" id="6"/>
                    </a>
               </d>
          </c>
     </b>
</a>

I'll appreciate any help ..

Regards,
Mukul



__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com



This message is for the designated recipient only and may contain privileged,
proprietary, or otherwise private information.  If you have received it in
error, please notify the sender immediately and delete the original.  Any
other use of the email by you is prohibited.

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.