Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSL Transformation 2

Status
Not open for further replies.

grega

Programmer
Feb 2, 2000
932
GB
I have an XML document of the form
[tt]
<ArrayOfSomething>
<Something>
<MyElement xmlns=" </Something>
<Something>
<MyElement xmlns=" </Something>
</ArrayOfSomething>
[/tt]

and an XSL transformation of the form
[tt]
<xsl:template match="ArrayOfSomething">
<xsl:for-each select="Something">
<xsl:value-of select="MyElement" />
<xsl:text>statictext</xsl:text>
</xsl:for-each>
</xsl:template>
[/tt]

When I run this transform all I'm getting is the statictext element - it doesn't seem to be picking up the MyElement element. I know this is to do with the xmlns attribute as when I remove it the transform works (I'm trying to address this separately - the source XML doc is the serialization of a complex type returned from a web service)

Any idea what expression (think it's xpath) I could use in the value-of element to pick up the element's value?

Any guidance appreciated.

Greg.
 
Greg,

You are correct about the namespace. Default namespaces create tricky problems, some of which I think will be addressed in XPath 2.0 specification.

How about [tt]select="*[local-name()=MyElement]"[/tt]? Perhaps that will do it...

Tom Morrison
 
Can declare the namespace in xsl with a name freely given to the default namespace of the set of elements. Then to match them, match them with fully-qualified name with such called namespace prefixed to them.
[tt]
<xsl:stylesheet version="1.0" xmlns:xsl=" [blue]xmlns:dfns="[/blue]>
<xsl:template match="ArrayOfSomething">
<xsl:for-each select="Something">
<xsl:value-of select="[blue]dfns:[/blue]MyElement" />
<xsl:text>statictext</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top