Output from document() is not formatted

Here should go questions about transforming XML with XSLT and FOP.
pvibhute
Posts: 1

Output from document() is not formatted

Fri Aug 10, 2018 7:22 am

Hello All,

I am new to XSLT & looking for the way to get formatted result from xslt.
Basically, I am invoking simple REST API through xslt as below -

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="/">
                <xsl:variable name="REST_response2"
                    select="document('http://localhost:8800/wmshead_fwh_django/wms/lgfapi/v9/entity/facility/647/facility_time_zone')" />
                <code1>
                    <xsl:value-of select="$REST_response2" />
                </code1>
        </xsl:template>
</xsl:stylesheet

Output I see is - 111Asia/Kolkata

If I run the same API through Postman, I return as below -

Code: Select all

{
    "result_count": 1,
    "page_count": 1,
    "page_nbr": 1,
    "next_page": null,
    "previous_page": null,
    "results": [
        {
            "code": "Asia/Kolkata"
        }
    ]
}

I have another question about passing authentication, not sure its relevant here but any thought/guideline will be helpful.
Query is, while executing this API through xslt. Is there any way, we can pass user/password on API through xslt ?
Radu
Posts: 5757

Re: Output from document() is not formatted

Fri Aug 10, 2018 8:11 am

Hi,

Maybe instead of xsl:value-of you should use "xsl:copy-of" instead, otherwise all the XML tags will be stripped from the copied content.
About the authentication, maybe it would be better to do that outside of the XSLT, have an ANT build file which downloads the necessary XML document from the web using authentication, then it stores it locally and invokes the XSLT stylesheet which reads the local XML and processes it.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Return to “XSLT and FOP”

Who is online

Users browsing this forum: No registered users and 0 guests