I have this .XML file:
<?xml version='1.0' encoding='utf-8'?>
<document id="random_id_doc" class"doc">
<properties>
<randomProperty name="name"><![CDATA[Name]]></randomProperty>
</properties>
<children>
<child id="random_id1" path="C:\random_id1.xml" class="image"/>
<child id="random_id2" path="C:\random_id2.xml" class="section"/>
</children>
</document>
And I need to extract the values from this XML to show it as HTML and also I need to extract the information of each children
as well.
Each children has a class, so I have to separate them depending on the class to which they belong. Let's say that for this example there are only two classes:
- image
- section
The structure of a child is the following:
<?xml version="1.0" encoding="UTF-8"?>
<object id="empty-section" class="section">
<properties>
<randomProperty name="name"><![CDATA[Name]]></randomProperty>
</properties>
<children>
<child id="random_id3" path="C:\random_id3.xml" class="image"/>
</children>
<traces />
</object>
As you can see they can also have children.
As far as I know, I tried to use document() XSLT function to get the document. I have also tried to call from the main template other templates:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exslt="http://exslt.org/common"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:proteus="https://proteus.us.es"
exclude-result-prefixes="exslt msxsl">
<xsl:output method="html" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes"/>
<!-- Object templates -->
<xsl:include href="objects/section.xslt" />
<xsl:include href="objects/image.xslt" />
<xsl:template match="/">
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.19/tailwind.min.css" integrity="sha512-wnea99uKIC3TJF7v4eKk4Y+lMz2Mklv18+r4na2Gn1abDRPPOeef95xTzdwGD9e6zXJBteMIhZ1+68QC5byJZw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
<body class="bg-white h-full">
<div class="mx-auto max-w-[210mm] w-full md:w-1/2 p-10 print:m-0 print:w-full">
<xsl:apply-templates />
</div>
</body>
</html>
</xsl:template>
<xsl:template match="document">
<!-- some Code for title -->
<!--Some code for document properties -->
<!-- Document objects -->
<xsl:for-each select="children/child">
<xsl:call-template name="child" />
</xsl:for-each>
</xsl:template>
<xsl:template name="child">
<xsl:call-template name="object"/>
<xsl:for-each select="children/child">
<xsl:call-template name="child"/>
</xsl:for-each>
</xsl:template>
<xsl:template name="object">
<xsl:variable name="class" select="@class"/>
<xsl:choose>
<xsl:when test="$class = 'section'">
<xsl:call-template name="section"/>
</xsl:when>
<xsl:when test="$class = 'image'">
<xsl:call-template name="image"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="section"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
And let's for for example section.xslt
I have tried several things but this one was the last one:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exslt="http://exslt.org/common"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:proteus="https://proteus.us.es" exclude-result-prefixes="exslt msxsl">
<xsl:output method="html" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes"/>
<xsl:template name="section" mode="call-template">
<xsl:variable name="path" select="@path"/>
<xsl:value-of select="document($path)/object/@id" disable-output-escaping="yes"/>
</xsl:template>
</xsl:stylesheet>
So basically it doesn't show anything. As far as I know the template is called properly because I tried to show the id <xsl:value-of select="@id" disable-output-escaping="yes"/>
and it worked. So I think the problem it's in the document function but I'm not sure at all.