XSLT转换,无需使用Saxon解析输入XML [英] XSLT transform without input XML with saxon parse

查看:101
本文介绍了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">
    &lt;products author=&quot;Jesper&quot;&gt;
      &lt;product id=&quot;p1&quot;&gt;
        &lt;name&gt;Delta&lt;/name&gt;
        &lt;price&gt;800&lt;/price&gt;
        &lt;stock&gt;4&lt;/stock&gt;
        &lt;country&gt;Denmark&lt;/country&gt;
      &lt;/product&gt;
      &lt;product id=&quot;p2&quot;&gt;
        &lt;name&gt;Golf&lt;/name&gt;
        &lt;price&gt;1000&lt;/price&gt;
        &lt;stock&gt;5&lt;/stock&gt;
        &lt;country&gt;Germany&lt;/country&gt;
      &lt;/product&gt;
      &lt;product id=&quot;p3&quot;&gt;
        &lt;name&gt;Alfa&lt;/name&gt;
        &lt;price&gt;1200&lt;/price&gt;
        &lt;stock&gt;19&lt;/stock&gt;
        &lt;country&gt;Germany&lt;/country&gt;
      &lt;/product&gt;
      &lt;product id=&quot;p4&quot;&gt;
        &lt;name&gt;Foxtrot&lt;/name&gt;
        &lt;price&gt;1500&lt;/price&gt;
        &lt;stock&gt;5&lt;/stock&gt;
        &lt;country&gt;Australia&lt;/country&gt;
      &lt;/product&gt;
      &lt;!-- p5 is a brand new product --&gt;
      &lt;product id=&quot;p5&quot;&gt;
        &lt;name&gt;Tango&lt;/name&gt;
        &lt;price&gt;1225&lt;/price&gt;
        &lt;stock&gt;3&lt;/stock&gt;
        &lt;country&gt;Japan&lt;/country&gt;
      &lt;/product&gt;
    &lt;/products&gt;
  </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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆