问题
Original question was here, now case slightly modified with saxon. I have following xsl tranformation:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:saxon="http://saxon.sf.net/">
<xsl:output method="xml" indent="yes" />
<xsl:param name="products">
<products author="Jesper">
<product id="p1">
<name>Delta</name>
<price>800</price>
<stock>4</stock>
<country>Denmark</country>
</product>
<product id="p2">
<name>Golf</name>
<price>1000</price>
<stock>5</stock>
<country>Germany</country>
</product>
<product id="p3">
<name>Alfa</name>
<price>1200</price>
<stock>19</stock>
<country>Germany</country>
</product>
<product id="p4">
<name>Foxtrot</name>
<price>1500</price>
<stock>5</stock>
<country>Australia</country>
</product>
<!-- p5 is a brand new product -->
<product id="p5">
<name>Tango</name>
<price>1225</price>
<stock>3</stock>
<country>Japan</country>
</product>
</products>
</xsl:param>
<xsl:param name="XMLproducts" select="saxon:parse($products)"></xsl:param>
<xsl:template match="@*|node()" >
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="products">
<xsl:copy>
<xsl:attribute name="dateUpdated">
<xsl:value-of select="current-dateTime()" />
</xsl:attribute>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="/" name="initial">
<xsl:apply-templates select="$XMLproducts"/>
</xsl:template>
</xsl:stylesheet>
When I run this with saxon 8 transformer, I get java.lang.StackOverflowError. Any ideas why this is happening and how to solve this?
回答1:
You construct a document and apply the templates to the document node where you construct the document again and apply the templates to the document node and so on.
So use
<xsl:template match="/" name="initial">
<xsl:apply-templates select="$XMLproducts/node()"/>
</xsl:template>
to prevent that problem.
来源:https://stackoverflow.com/questions/27379248/xslt-transform-without-input-xml-with-saxon-parse