Reputation: 763
I am trying to get a value from a variable within an XSLT document. Here is my code:
<?xml version="1.0" encoding="utf-8"?>
<xsl:template match="/">
<Composition xmlns="Playlist">
<xsl:variable name="source_var">
<Source identifier="0">Inside Source</Source>
</xsl:variable>
<Video>
<xsl:value-of select="ms:node-set($source_var)/Source"/>
</Video>
</Composition>
</xsl:template>
Its not working. The output is this:
<Composition xmlns="Playlist">
<Video></Video>
</Composition>
When it should be this:
<Composition xmlns="Playlist">
<Video>Inside Source</Video>
</Composition>
When I remove the namespace xmlns="Playlist"
from the <Composition>
tag it works. So I am think it has to do with the name space, but I have to keep the namespace in.
I feel the ms:node-set($source_var)/Source
is looking in the wrong namespace, but I dont know how to fix the probelem.
Upvotes: 0
Views: 265
Reputation: 167716
Change
<xsl:variable name="source_var">
<Source identifier="0">Inside Source</Source>
</xsl:variable>
to
<xsl:variable name="source_var" xmlns="">
<Source identifier="0">Inside Source</Source>
</xsl:variable>
if you can, or to
<xsl:variable name="source_var">
<Source xmlns="" identifier="0">Inside Source</Source>
</xsl:variable>
If you can't change the namespace of the element then you need to use a prefix in your path e.g. you need
<xsl:value-of select="ms:node-set($source_var)/ns1:Source" xmlns:ns1="Playlist"/>
Of course instead of putting the declaration on the value-of
you can also put it on the xsl:stylesheet
.
Upvotes: 1