This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: conditional namespaces


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]