Reputation: 3569
and also the indent does not work!
I need to generate an XML file from small files, so I tried using XSL to merge all files, but it does not work as expected.
When viewing "devices.xml" when all files are uploaded to a site:
and when I use "File | save as" -
When viewing "devices.xml" as local file:
My questions:
source files:
devices.xml
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="./mergedocs.xsl" ?>
<device_list>
<file name="./device1.xml" />
<file name="./device2.xml" />
</device_list>
device1.xml
<d>
<i1 v="11" />
<i2 v="11" />
</d>
device2.xml
<d>
<i1 v="22" />
<i2 v="22" />
</d>
probes1.xml
<p name="probes1">
<Item>"1 Name Pb1"</Item>
<Item>"2 Name Pb1"</Item>
</p>
probes2.xml
<p name="probes2">
<Item>"1 Name Pb2"</Item>
<Item>"2 Name Pb2"</Item>
</p>
mergedocs.xsl
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" />
<xsl:variable name="probes1" select="document('probes1.xml')" />
<xsl:variable name="probes2" select="document('probes2.xml')" />
<xsl:template match="/">
<myRoot>
<xsl:for-each select="/device_list/file">
<device>
<xsl:variable name="k" select="position()" />
<xsl:apply-templates select="document(@name)/d" >
<xsl:with-param name="strK" select="$k"/>
</xsl:apply-templates>
</device>
</xsl:for-each>
</myRoot>
</xsl:template>
<xsl:template match="d">
<xsl:param name="strK" />
<xsl:apply-templates >
<xsl:with-param name="strK" select="$strK"/>
</xsl:apply-templates >
</xsl:template>
<xsl:template match="i1">
<xsl:param name="strK" />
<input1>
<name><xsl:value-of select="$probes1//Item[position() = $strK]"/></name>
<value><xsl:value-of select="@v" /></value>
</input1>
</xsl:template>
<xsl:template match="i2">
<xsl:param name="strK" />
<input2>
<name><xsl:value-of select="$probes2//Item[position() = $strK]"/></name>
<value><xsl:value-of select="@v" /></value>
</input2>
</xsl:template>
</xsl:stylesheet>
Upvotes: 1
Views: 1366
Reputation: 163302
The XSLT processors built in to the browser, especially when invoked using the xml-stylesheet PI, assume that you are generating HTML, and display the result as if it were HTML. This basically means ignoring all tags that have no meaning in HTML, so you just end up with the text.
From the description of what you are trying to achieve, it's not clear to me why you are trying to run this in the browser. You would be far better off using an XSLT processor you can run from the command line or from a GUI.
Upvotes: 3