including data from a separate xml-file
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 4
- Joined: Thu Dec 25, 2008 7:00 pm
including data from a separate xml-file
A external application is sending error-xml-files as respond.xml, if an error occures. I try to transform these Messages into a readeble text. But the respond.xml has only error-codes. But I would like to see the real error-message, wich I can find in errors.xml
Is it possible to combine my xslt to errors.xml?
How could I include that errors.mxl to my xslt-File rtest.xsl?
Thank you for your help!
Joseph
A respond.xml looks abot like this:
The errors.xml is like this:
And my xslt-File looks this way:
Is it possible to combine my xslt to errors.xml?
How could I include that errors.mxl to my xslt-File rtest.xsl?
Thank you for your help!
Joseph
A respond.xml looks abot like this:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<invoice:response xmlns:invoice="abc">
<invoice:invoice invoice_id="9549">
</invoice:invoice>
<invoice:status>
<invoice:rejected>
<invoice:error error="101"/>
<invoice:error error="103"/>
</invoice:rejected>
</invoice:status>
</invoice:response>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<errors>
<error_id>101</error_id>
<message>invalid address</message>
<error_id>102</error_id>
<message>invalid amount</message>
<error_id>103</error_id>
<message>wrong currency</message>
</errors>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="invoice:status" xmlns:invoice="abc">
<xsl:if test="invoice:rejected"> Responsetyp: Rejected
<xsl:for-each
select="invoice:rejected/invoice:error"> Error: <xsl:value-of select="@error"/>
<!-- Here should be the error-message from errors.xml-->
</xsl:for-each>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
-
- Posts: 4
- Joined: Thu Dec 25, 2008 7:00 pm
Re: including data from a separate xml-file
I have found a solution.
First I had to separate the errors in errors.xml:
<?xml version="1.0" encoding="UTF-8"?>
Then in the XSLT I linked the errors.xml:
First I had to separate the errors in errors.xml:
<?xml version="1.0" encoding="UTF-8"?>
Code: Select all
<response>
<errors>
<message_id>101</message_id>
<message>invalid address</message>
</errors>
<errors>
<message_id>102</message_id>
<message>invalid amount</message>
</errors>
<errors>
<message_id>103</message_id>
<message>wrong currency</message>
</errors>
</response>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="invoice:status" xmlns:invoice="abc">
<xsl:if test="invoice:rejected"> Responsetyp: Rejected
<xsl:for-each
select="invoice:rejected/invoice:error">
<xsl:variable name="v_error_id" select="@error"/>
Error_id: <xsl:value-of select="$v_error_id" />
Error: <xsl:value-of select="document('errors.xml')/response/errors[message_id=$v_error_id]/message"/>
</xsl:for-each>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Re: including data from a separate xml-file
Yes, you can use the document function to access data from another file. Note however that you do not necessary need to change the structure of the errors file as you can access the message using the following sibling axis, see for example
Best Regards,
George
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="invoice:status" xmlns:invoice="abc">
<xsl:if test="invoice:rejected"> Responsetyp: Rejected
<xsl:for-each
select="invoice:rejected/invoice:error">
<xsl:text> Error: </xsl:text>
<xsl:value-of select="@error"/>
<!-- Here should be the error-message from errors.xml-->
<xsl:text> </xsl:text>
<xsl:value-of
select="document('errors.xml')/errors/error_id[.=current()/@error]/following-sibling::message[1]"/>
</xsl:for-each>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
George
George Cristian Bina
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