namespace problem when generating HTML
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 32
- Joined: Wed Jan 25, 2006 5:43 pm
namespace problem when generating HTML
Hi,
I'm trying to generate HTML out of an XML doccument - so far, so good. The problem is that the XML document uses a namespace defined in the related XSD.
When I remove the namespace information from the XML file the HTML file is generated, otherwise the elements are not recognized and the output remains empty.
Any idea on how to make the namespace and thus the elements available in the XSLT? Just adding the same information as in the XML file does not do the trick.
Best regards
- Alex
I'm trying to generate HTML out of an XML doccument - so far, so good. The problem is that the XML document uses a namespace defined in the related XSD.
When I remove the namespace information from the XML file the HTML file is generated, otherwise the elements are not recognized and the output remains empty.
Any idea on how to make the namespace and thus the elements available in the XSLT? Just adding the same information as in the XML file does not do the trick.
Best regards
- Alex
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Hi Alex,
You need to change the name tests to use the prefix. For instance if you have something like
<xsl:template match="test">
that will match the test element from no namespace. As you have in your document test in some namespace then you need to use somthing like
<xsl:template match="x:test">
where x is mapped to your element namespace.
If you are using XSLT 2.0 adding an attribute:
xpath-default-namespace="yourNamespaceHere"
on your xsl:stylesheet element should be enough as support for default namespace was added starting with XSLT 2.0.
Best Regards,
George
You need to change the name tests to use the prefix. For instance if you have something like
<xsl:template match="test">
that will match the test element from no namespace. As you have in your document test in some namespace then you need to use somthing like
<xsl:template match="x:test">
where x is mapped to your element namespace.
If you are using XSLT 2.0 adding an attribute:
xpath-default-namespace="yourNamespaceHere"
on your xsl:stylesheet element should be enough as support for default namespace was added starting with XSLT 2.0.
Best Regards,
George
-
- Posts: 32
- Joined: Wed Jan 25, 2006 5:43 pm
Hi George,
thanks for you answer. The problem is that my namespace has no prefix that I could add. All my XSD stuff has MathML as namespace (xmlns="http://www.w3.org/1998/Math/MathML"). When I remove this from the XML file the transformation works.
xpath-default-namespace I had already tried with little success.
My XML file starts like this:
<top xmlns="http://www.w3.org/1998/Math/MathML" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/1998/Math/MathML XSD\myxsd.xsd">
the XSLT looks like this:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xpath-default-namespace="http://www.w3.org/1998/Math/MathML XSD\myxsd.xsd">
Any idea???
Cheers
- Alex
thanks for you answer. The problem is that my namespace has no prefix that I could add. All my XSD stuff has MathML as namespace (xmlns="http://www.w3.org/1998/Math/MathML"). When I remove this from the XML file the transformation works.
xpath-default-namespace I had already tried with little success.
My XML file starts like this:
<top xmlns="http://www.w3.org/1998/Math/MathML" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/1998/Math/MathML XSD\myxsd.xsd">
the XSLT looks like this:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xpath-default-namespace="http://www.w3.org/1998/Math/MathML XSD\myxsd.xsd">
Any idea???
Cheers
- Alex
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Hi Alex,
xpath-default-namespace="http://www.w3.org/1998/Math/MathML XSD\myxsd.xsd">
The namespace is only the first part, that is http://www.w3.org/1998/Math/MathML. The second part is the schema document and in general that is used as a hint for the XML Schema processor but that is not part of the namespace. Try using:
xpath-default-namespace="http://www.w3.org/1998/Math/MathML"
Best Regards,
George
xpath-default-namespace="http://www.w3.org/1998/Math/MathML XSD\myxsd.xsd">
The namespace is only the first part, that is http://www.w3.org/1998/Math/MathML. The second part is the schema document and in general that is used as a hint for the XML Schema processor but that is not part of the namespace. Try using:
xpath-default-namespace="http://www.w3.org/1998/Math/MathML"
Best Regards,
George
-
- Posts: 71
- Joined: Fri Apr 30, 2004 8:00 pm
- Location: Texas
Hi,
I've got a similar problem, but your solution didn't seem to help me.
I'm trying to parse the output from OpenOffice, here's a paired down example:
Right now I'd be happy just to xpath into the 'Cell' element, so my xsl looks like:
However my output is not what I would expect.
All I get is the default template processing for the Cell elements
Anyone have better eyes than me and can see what I've left out?
I should add, if I remove the default namespace (or give it a prefix) then the processing works just as I would expect it would.
It is the default namespace in the XML file that's causing me fits.
Thanks,
I've got a similar problem, but your solution didn't seem to help me.
I'm trying to parse the output from OpenOffice, here's a paired down example:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?><?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet">
<Cell>Inside the Cell 1</Cell>
<Cell>Inside the Cell 2</Cell>
</Workbook>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xpath-default-namespace="urn:schemas-microsoft-com:office:spreadsheet">
<xsl:template match="/Workbook">
<p>AAAAAA</p>
<xsl:apply-templates select="Cell"></xsl:apply-templates>
</xsl:template>
<xsl:template match="Cell">
My Cell
</xsl:template>
</xsl:stylesheet>
All I get is the default template processing for the Cell elements
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
Inside the Cell 1
Inside the Cell 2
I should add, if I remove the default namespace (or give it a prefix) then the processing works just as I would expect it would.
Code: Select all
<?xml version="1.0" encoding="utf-8"?><p>AAAAAA</p>
My Cell
My Cell
Thanks,
--------------------------
- mike
GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876
- mike
GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
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