Can't match namespace nodes with <xsl:template match>
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 6
- Joined: Fri Jul 07, 2006 10:34 pm
Can't match namespace nodes with <xsl:template match>
I'm doing an XML to XML conversion using the identiy transformation code piece first before processing the namespace nodes. For some reason the sky:datasource tags aren't being matched at all. If I remove the sky: namespace, then I can match them after also removing it from the XSL style sheet. In the sample below i'm trying to add an element called <sky:testnode> inside the <sky:datasource> node(s). When I run the XSL everything is copied and passed through, but the new element is never added.
Here is my XML:
Here is my XSL stylesheet:
After the new element is copied, I need strip out the unwanted xmlns:sky attribute that was added inside the new node.
Here is my XML:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="NamespaceMatching.xsl"?>
<sky:item xmlns:sky="http://tempuri.com/item">
<sky:datasource id="LikertScale">
<sky:dataitem text="Unimportant" value="0"/>
<sky:dataitem text="Don't Care" value="1"/>
<sky:dataitem text="Important" value="2"/>
</sky:datasource>
<sky:datasource id="LikertScale2">
<sky:dataitem text="Unimportant" value="3"/>
<sky:dataitem text="Don't Care" value="4"/>
<sky:dataitem text="Important" value="5"/>
</sky:datasource>
</sky:item>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sky="http://ctlt.wsu.edu/skylight/sky">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- the standard identity transformation -->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="sky:datasource">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
<xsl:element name="sky:testnode"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Hi,
The namespace is not sky, sky is a prefix and it is used to refer to the namespace it is bound to. The problem is that you have sky mapped to different namespaces in your document it is mapped to http://tempuri.com/item while in your stylesheet you map it to http://ctlt.wsu.edu/skylight/sky. If you change for instance in the stylesheet to replace
xmlns:sky="http://ctlt.wsu.edu/skylight/sky"
with
xmlns:sky="http://tempuri.com/item"
then you should get the behaviour you expect.
Best Regards,
George
The namespace is not sky, sky is a prefix and it is used to refer to the namespace it is bound to. The problem is that you have sky mapped to different namespaces in your document it is mapped to http://tempuri.com/item while in your stylesheet you map it to http://ctlt.wsu.edu/skylight/sky. If you change for instance in the stylesheet to replace
xmlns:sky="http://ctlt.wsu.edu/skylight/sky"
with
xmlns:sky="http://tempuri.com/item"
then you should get the behaviour you expect.
Best Regards,
George
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service