Transform fails when xmlns namespace declaration present
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 2
- Joined: Mon Sep 26, 2005 9:32 pm
Transform fails when xmlns namespace declaration present
I have a DSML document that declares a default namespace. When the xmlns attribute is present, the transform does not return the desired results. When I remove the attribute, the transform works as expected.
I am trying to learn what I am not understanding about the roll of the namespace declaration relative to what the transform process is needing.
The namespace declaration is present by default as I am using a binary DSML toolset distribution that always includes it. Note that the URL http://www.dsml.org/DSML returns a 404 as dsml.org is no longer maintained.
I appreciate any suggestions that help me understand how the namespace declaration is impacting this simple transform process.
The stylesheet is as follows:
Successful output:
I am trying to learn what I am not understanding about the roll of the namespace declaration relative to what the transform process is needing.
The namespace declaration is present by default as I am using a binary DSML toolset distribution that always includes it. Note that the URL http://www.dsml.org/DSML returns a 404 as dsml.org is no longer maintained.
I appreciate any suggestions that help me understand how the namespace declaration is impacting this simple transform process.
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<dsml complete="false" xmlns="http://www.dsml.org/DSML">
<directory-entries>
<entry dn="dc=qua,dc=company,dc=com">
<objectclass>
<oc-value>top</oc-value>
<oc-value>domain</oc-value>
</objectclass>
<attr name="dc">
<value>qua</value>
</attr>
</entry>
<entry dn="cn=Directory Administrators, dc=qua,dc=company,dc=com">
<objectclass>
<oc-value>top</oc-value>
<oc-value>groupofuniquenames</oc-value>
</objectclass>
<attr name="cn">
<value>Directory Administrators</value>
</attr>
</entry>
<entry dn="ou=Groups, dc=qua,dc=company,dc=com">
<objectclass>
<oc-value>top</oc-value>
<oc-value>organizationalunit</oc-value>
</objectclass>
<attr name="ou">
<value>Groups</value>
</attr>
</entry>
<entry dn="ou=People, dc=qua,dc=company,dc=com">
<objectclass>
<oc-value>top</oc-value>
<oc-value>organizationalunit</oc-value>
</objectclass>
<attr name="ou">
<value>People</value>
</attr>
</entry>
</directory-entries>
</dsml>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="entry">
<dn>
<xsl:value-of select="./@dn"/>
</dn>
</xsl:template>
</xsl:stylesheet>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<dn>dc=qua,dc=company,dc=com</dn>
<dn>cn=Directory Administrators, dc=qua,dc=company,dc=com</dn>
<dn>ou=Groups, dc=qua,dc=company,dc=com</dn>
<dn>ou=People, dc=qua,dc=company,dc=com</dn>
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Hi,
When you say
<xsl:template match="entry">
that means the template will match on entry elements from no namespace.
If you do not have the default namespace declaration in your XML file then the entry elements belong to no namespace and are matched by your template. If you add the default namespace declaration xmlns="http://www.dsml.org/DSML" then the entry elements belong to the "http://www.dsml.org/DSML" namespace and are not matched anymore by your template. You need to declare the "http://www.dsml.org/DSML" in your stylesheet using a prefix (note that XPath does not handle default namespace so you need a prefix) and use that to qualify the entry element in the match attribute, something like:
Best Regards,
George
When you say
<xsl:template match="entry">
that means the template will match on entry elements from no namespace.
If you do not have the default namespace declaration in your XML file then the entry elements belong to no namespace and are matched by your template. If you add the default namespace declaration xmlns="http://www.dsml.org/DSML" then the entry elements belong to the "http://www.dsml.org/DSML" namespace and are not matched anymore by your template. You need to declare the "http://www.dsml.org/DSML" in your stylesheet using a prefix (note that XPath does not handle default namespace so you need a prefix) and use that to qualify the entry element in the match attribute, something like:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:d="http://www.dsml.org/DSML">
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="d:entry">
<dn>
<xsl:value-of select="./@dn"/>
</dn>
</xsl:template>
</xsl:stylesheet>
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