cant reach data in xml with namespaces
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 5
- Joined: Fri Mar 24, 2006 6:32 pm
cant reach data in xml with namespaces
Hi!
I have a problem retriving data from xml file.
XML:
XSLT:
...why do i get blank output?
Thank you for your help.
I have a problem retriving data from xml file.
XML:
Code: Select all
<?xml version="1.0" encoding="utf-8" ?>
<Data xmlns="http://something.com/Documents/Schemas/doc.xsd"
xmlns:e="http://something.com/Documents/Schemas/file.xsd">
<e:Head>
<e:name>John</e:name>
<e:address1>London, UK</e:address1>
<e:postNumber>123456</e:postNumber>
</e:Head>
<body>
<age>35</age>
<kids>3</kids>
<car>ford</car>
</body>
</Data>
XSLT:
Code: Select all
<?xml version="1.0" encoding="windows-1250" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:edp="http://http://something.com/Documents/Schemas/file.xsd">
<xsl:template match="/">
<xsl:value-of select="//Data/e:Head/e:name" />
<xsl:value-of select="//Data/Body/age" />
</xsl:template>
</xsl:stylesheet>
...why do i get blank output?
Thank you for your help.
-
- Posts: 5
- Joined: Fri Mar 24, 2006 6:32 pm
in posted xslt there is a typing error in 3rd line:
xmlns:edp="http://http://something.com/Documents/Schemas/file.xsd">
should be:
xmlns:e="http://http://something.com/Documents/Schemas/file.xsd">
...this does not solve the problem from the first post.
Thanks again for your help.
xmlns:edp="http://http://something.com/Documents/Schemas/file.xsd">
should be:
xmlns:e="http://http://something.com/Documents/Schemas/file.xsd">
...this does not solve the problem from the first post.
Thanks again for your help.
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Hi,
You have a default namespace declared in your Data element and that makes all the elements without a prefix to belong to that default namespace. On the other hand in the stylesheet you match on similar local names as the names of the elements from the default namespce in your document but you match elements from no namespace. The solution is to define your document default namespace also in the stylesheet using some prefix and then use that prefix to qualify the element names in order to correclty refer to those elements from their namespace.
Also note that XML is case sensitive so body and Body are different things.
Bellow you can find a working stylesheet:
Best Regards,
George
You have a default namespace declared in your Data element and that makes all the elements without a prefix to belong to that default namespace. On the other hand in the stylesheet you match on similar local names as the names of the elements from the default namespce in your document but you match elements from no namespace. The solution is to define your document default namespace also in the stylesheet using some prefix and then use that prefix to qualify the element names in order to correclty refer to those elements from their namespace.
Also note that XML is case sensitive so body and Body are different things.
Bellow you can find a working stylesheet:
Code: Select all
<?xml version="1.0" encoding="windows-1250" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:e="http://something.com/Documents/Schemas/file.xsd"
xmlns:d="http://something.com/Documents/Schemas/doc.xsd">
<xsl:template match="/">
<xsl:value-of select="//d:Data/e:Head/e:name" />
<xsl:value-of select="//d:Data/d:body/d:age" />
</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