How to add more namespaces to one element by XSLT
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 2
- Joined: Sat Feb 02, 2019 7:42 pm
How to add more namespaces to one element by XSLT
Hi,
I am sorry but I am desparate. I am new to XSLT developing and I thought that it will be easy but the creating of XSLT that will do exactly what I want is not so easy.
I need to add more namespaces to one element by XSLT.
See. I need to create this XML file:
There is used the namespace prefix "inv" for invoice "inv:invoice" and then for invoiceHeader there are used two prefixes like "typ" and "rsp". Of cousre I can create it in text editor and it works but i need to create it automaticaly by XSLT template so I can automate the invoices that I have in XML file from our supplier.
I have created this XSLT file:
But it does not generate the result I need. Please can somebody help say how to add more namespaces with prefixes to one element y XSLT?
Best Reagrds
I am sorry but I am desparate. I am new to XSLT developing and I thought that it will be easy but the creating of XSLT that will do exactly what I want is not so easy.
I need to add more namespaces to one element by XSLT.
See. I need to create this XML file:
Code: Select all
<?xml version="1.0" encoding="Windows-1250"?>
<inv:invoice version="2.0" xmlns:inv="http://www.stormware.cz/schema/version_2/invoice.xsd">
<inv:invoiceHeader xmlns:typ="http://www.stormware.cz/schema/version_2/type.xsd" xmlns:rsp="http://www.stormware.cz/schema/version_2/response.xsd" >
</inv:invoiceHeader>
</inv:invoice>
I have created this XSLT file:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:attribute-set name="ver">
<xsl:attribute name="version">2.0</xsl:attribute>
</xsl:attribute-set>
<xsl:template match="/">
<xsl:element name="inv:invoice" namespace="http://www.stormware.cz/schema/version_2/invoice.xsd" use-attribute-sets="ver">
<xsl:element name="inv:invoiceHeader" namespace="http://www.stormware.cz/schema/version_2/invoice.xsd" xmlns:typ="http://www.stormware.cz/schema/version_2/type.xsd" xmlns:rsp="http://www.stormware.cz/schema/version_2/response.xsd">
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Best Reagrds
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: How to add more namespaces to one element by XSLT
Hi,
Maybe you can try to use the <xsl:namespace> element:
https://www.w3.org/TR/xslt20/#element-namespace
Regards,
Radu
Maybe you can try to use the <xsl:namespace> element:
https://www.w3.org/TR/xslt20/#element-namespace
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 2
- Joined: Sat Feb 02, 2019 7:42 pm
Re: How to add more namespaces to one element by XSLT
Thank you very much. It works. Actually I have tried it before but ti does not work because I tried it to add to the Element. Today I have test it again and it works but if I add the textuatl element not to xsl:element.
See this example:
It create the element name "inv:invoiceHeader" with namespace prefix "typ" and then under this element there is used <typ:ids> and it is known.
When I put xmlns:typ to the xsl:namespace name then this does not work, see:
it does not work with error:
Error 1 at line 25:24 : Error reported by XML parser: The prefix "typ" for element "typ:ids" is not bound.
Best Regards
See this example:
Code: Select all
<xsl:element name="inv:invoiceHeader" xmlns:typ="http://www.stormware.cz/schema/version_2/type.xsd">
<xsl:namespace name = "rsp" select = "'http://www.stormware.cz/schema/version_2/response.xsd'" />
<xsl:namespace name = "lst" select = "'http://www.stormware.cz/schema/version_2/list.xsd'" />
<inv:accounting>
<typ:ids>1Fp</typ:ids>
</inv:accounting>
</xsl:element>
When I put xmlns:typ to the xsl:namespace name then this does not work, see:
Code: Select all
<xsl:element name="inv:invoiceHeader">
<xsl:namespace name = "rsp" select = "'http://www.stormware.cz/schema/version_2/response.xsd'" />
<xsl:namespace name = "lst" select = "'http://www.stormware.cz/schema/version_2/list.xsd'" />
<xsl:namespace name = "typ" select = "'http://www.stormware.cz/schema/version_2/type.xsd'" />
<inv:accounting>
<typ:ids>1Fp</typ:ids>
</inv:accounting>
</xsl:element>
Error 1 at line 25:24 : Error reported by XML parser: The prefix "typ" for element "typ:ids" is not bound.
Best Regards
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: How to add more namespaces to one element by XSLT
Hi,
If in the XSLT stylesheet you output elements using constructs like this:
you will still need to declare a namespace for the prefix xmlns:typ="http://www.stormware.cz/schema/version_2/type.xsd" usually directly on the xsl:stylesheet root element.
So declaring prefix namespace mappings in the XSLT stylesheet using "xsl:namespace" is usually not needed because you already declare the prefix to namespace mappings in the XSLT stylesheets in order to properly output the elements.
Regards,
Radu
If in the XSLT stylesheet you output elements using constructs like this:
Code: Select all
<typ:ids>1Fp</typ:ids>
So declaring prefix namespace mappings in the XSLT stylesheet using "xsl:namespace" is usually not needed because you already declare the prefix to namespace mappings in the XSLT stylesheets in order to properly output the elements.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
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