Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: match attribute for xsl:template

From: Marvin Smit <marvin.smit@-----.--->
To: NULL
Date: 11/8/2005 10:18:00 AM
Hi,

Although i'm unable to test other dev tools (MSXML or Xalan) i just
did with .Net 1.1

The .Net XSLT class chokes on the compilation of these XSLT's. I tried
locating some info @ W3C but couldn't find this specific topic. (I
might have missed it).

I remember doing something similar, but the first post obviously
doesn't work in .Net (not sure in other parsers).

I couldn't resist 'trying to solve the functionality question' and
this is what i came up with:

<?xml version="1.0" encoding="UTF-8" ?>
<stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" />
	<xsl:param name="ElementName" />
	<xsl:param name="NamespaceURI"    />
	
	<xsl:template match="/">
		<xsl:element name="root">
			<xsl:apply-templates select="child::*" />
		</xsl:element>
	</xsl:template>
	
	<xsl:template match="node()">
		<xsl:variable name="ElemsToProcess"
select="*[local-name()=$ElementName and
namespace-uri()=$NamespaceURI]" />
		<xsl:if test="count($ElemsToProcess) &gt; 0">
			<xsl:call-template name="doit">
				<xsl:with-param name="ElemsToProcess"
select="$ElemsToProcess" />
			</xsl:call-template>
		</xsl:if>			
		<xsl:apply-templates select="child::*" />
	</xsl:template>	

	<xsl:template name="doit">
		<xsl:param name="ElemsToProcess" />
		<xsl:for-each select="$ElemsToProcess">
			<xsl:element name="output">
				<xsl:text>The element name =
</xsl:text>
				<xsl:value-of select="local-name()" />
				<xsl:text>&#10;</xsl:text>
				<xsl:text>The element resides in
namespace = </xsl:text>
				<xsl:value-of select="namespace-uri()"
/>
				<xsl:text>&#10;</xsl:text>
				<xsl:text>The element has the content
= </xsl:text>
				<xsl:value-of select="." />
				<xsl:text>&#10;</xsl:text>
			</xsl:element>
		</xsl:for-each>
	</xsl:template>
	
	<xsl:template match="text()"></xsl:template>

</stylesheet>


This template accepts a "ElementName" & "NamespaceURI" and will
execute the template called "doit" for each one found.

The real question becomes.. what is the intended functionality for
this?

Hope this helps,

Marvin Smit

On Mon, 07 Nov 2005 21:13:30 +0000, Peter Flynn
<peter.nosp@m...> wrote:

>Oleg Tkachenko [MVP] wrote:
>
>> Marvin Smit wrote:
>> 
>>> you could do the following approach (with parameters):
>>> 
>>> <xsl:param name='param1' />
>>> <xsl:param name='param2' />
>>> 
>>> <xsl:template match="*[local-name()=$param1 and
>>> namespace-uri()=$param2]" />
>> 
>> No, variable references cannot be used in match, even within a
>> predicate.
>
>Parameter references can: 
>
><?xml version="1.0" encoding="ISO-8859-1"?>
><doc>
>  <foo>bar</foo>
>  <bar>foo</bar>
></doc>
>
><?xml version="1.0" encoding="iso-8859-1"?>
><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>                version="1.0">
>
>  <xsl:output method="html"/>
>  <xsl:param name="ename"/>
>
>  <xsl:template match="*[name()=$ename]">
>    <blort>
>      <xsl:value-of select="."/>
>    </blort>
>  </xsl:template>
>
></xsl:stylesheet>
>
>///Peter


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent