XSLT转换,无需使用Saxon解析输入XML [英] XSLT transform without input XML with saxon parse
本文介绍了XSLT转换,无需使用Saxon解析输入XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
最初的问题是此处,现在是案例撒克逊人略加修改.我有以下xsl转换:
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>
当我使用saxon 8转换器运行它时,出现java.lang.StackOverflowError.为什么会发生这种情况以及如何解决这个问题的任何想法?
When I run this with saxon 8 transformer, I get java.lang.StackOverflowError. Any ideas why this is happening and how to solve this?
推荐答案
您构造文档并将模板应用于文档节点,然后再次构造文档并将模板应用于文档节点,依此类推.
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.
所以使用
<xsl:template match="/" name="initial">
<xsl:apply-templates select="$XMLproducts/node()"/>
</xsl:template>
防止出现此问题.
这篇关于XSLT转换,无需使用Saxon解析输入XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文