[xsl] Conflicting templates?

Subject: [xsl] Conflicting templates?
From: "Robert Soesemann" <rsoesemann@xxxxxxxxxxx>
Date: Fri, 17 Dec 2004 12:25:24 +0100
It seems that there is a conflict between the two templates in the
following xsl.

The first one adds the xsd association and the second iterates over all
node and convert @name @type values to element names if available. But
the new attribute does not appear in the result document although I copy
attributes with <xsl:copy-of>. Is there a conflict between the
templates?

Robert
---


<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>

	<!-- Include global XSL message template -->
	<xsl:include href="globals.xsl"/>

	<!-- Parameter will be filled by ant target -->
	<xsl:param name="validator-url" />


	<!-- 1. Add XMLSchema sssociation to root node -->
	<xsl:template match="/*">
		<xsl:copy>
			<!-- add association to general kiwi validator
xsd -->
			<xsl:attribute
name="xsi:noNamespaceSchemaLocation">
				<xsl:value-of select="$validator-url"/>
			</xsl:attribute>

			<xsl:copy-of select="@*"/>
			<xsl:apply-templates />
		</xsl:copy>
	</xsl:template>

 	<xsl:template match="node()[starts-with(name(),'my-')">
		<xsl:variable name="element-name">
			<xsl:choose>
				<xsl:when test="@name != ''">
					<xsl:value-of select="@name"/>
				</xsl:when>
				<xsl:when test="@type != ''">
					<xsl:value-of select="@type"/>
				</xsl:when>
				<xsl:otherwise></xsl:otherwise>
			</xsl:choose>
		</xsl:variable>

		<xsl:choose>
			<xsl:when test="$element-name != ''">
				<xsl:element name="{$element-name}">
					<xsl:copy-of select="@*"/>
					<xsl:apply-templates />
				</xsl:element>
			</xsl:when>
			<xsl:otherwise>
				<xsl:copy>
					<xsl:copy-of select="@*"/>
					<xsl:apply-templates />
				</xsl:copy>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

</xsl:stylesheet>

-----Original Message-----
From: David Carlisle [mailto:davidc@xxxxxxxxx]
Sent: Freitag, 17. Dezember 2004 11:39
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Add attribute to root node



root nodes (/) represent the whole document and can not have attributes,
the children of the root node are the top level element and any
commeents or processing instructions that occur before or after that
element.

presumably you want to add an attribute to the top level element which
is /* not /

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. For more information on a proactive anti-virus
service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Current Thread