This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: conditional namespaces
- From: ronald heller <ronald at salience dot nl>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Mon, 17 Dec 2001 10:26:56 +0100
- Subject: Re: [xsl] conditional namespaces
- References: <000201c184b9$6fb2a780$6701a8c0@DHOOKER>
- Reply-to: xsl-list at lists dot mulberrytech dot com
I want to thank you all for your helpfull replies. I know I didn't declare
the namespace and the prefix, and that this would be a problem.
Both were variables , the prefix I get as a parameter, and the namespace
uri is the result of of concat.
Maybe a bit weird, but it is exactly what we needed.
I solved it with the help of your comments , and I want to share the xsl I
came up with. Just so anyone who followed this thread is able to look at
the result, and maybe give some comments on it :-)
Here we go:
XML:
<document>
<title>google</title>
<a>aaa</a>
</document>
XSLT:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="attribute">type</xsl:param>
<xsl:param name="value">gg</xsl:param>
<xsl:param name="namespace-prefix">ns</xsl:param>
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
<xsl:template match="document">
<xsl:variable name="namespace"
select="concat('http://www.',title,'.com')"/>
<document>
<xsl:attribute name="{concat($namespace-prefix,':',$attribute)}"
namespace="{$namespace}">
<xsl:value-of select="$value" />
</xsl:attribute>
<xsl:apply-templates/>
<xsl:comment>
Namespace-prexix: <xsl:value-of select="$namespace-prefix"/>
Namespace URI : <xsl:value-of select="$namespace"/>
</xsl:comment>
</document>
</xsl:template>
</xsl:stylesheet>
Once again thank you Jeni, Trever and Mike
RH
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list