【问题标题】:Freemarker - XSLT equivalent of copy-ofFreemarker - XSLT 等价于副本
【发布时间】:2018-09-06 04:06:19
【问题描述】:

我正在尝试在 XSLT 中模拟复制功能,我希望节点内的所有内容都在响应中输出。

使用这个模板

<#ftl ns_prefixes={"D": "http://milyn.codehaus.org/Smooks"} output_format="XML">
${Order.orderitem.@@markup}

这里有两个问题

  1. 我得到的输出转换为 以及 XML 标记。我确实需要 XML 格式来转义 & 等无效字符。

  2. 如何删除出现在每个节点中的名称景观

我的回答是

&lt;orderitem xmlns=&quot;http://milyn.codehaus.org/Smooks&quot;&gt;&lt;position&gt;1&lt;/position&gt;&lt;quantity&gt;1&lt;/quantity&gt;&lt;productid&gt;364&lt;/productid&gt;&lt;title&gt;The 40YearOld&lt;/title&gt;&lt;price&gt;29.98&lt;/price&gt;&lt;/orderitem&gt;&lt;orderitem xmlns=&quot;http://milyn.codehaus.org/Smooks&quot;&gt;&lt;position&gt;2&lt;/position&gt;&lt;quantity&gt;1&lt;/quantity&gt;&lt;productid&gt;299&lt;/productid&gt;&lt;title&gt;Pulp Fiction&lt;/title&gt;&lt;price&gt;29.99&lt;/price&gt;&lt;/orderitem&gt;

输入是

<Order xmlns="http://milyn.codehaus.org/Smooks" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance">
<header>
    <orderid>1</orderid>
    <statuscode>0</statuscode>
    <netamount>59.97</netamount>
    <totalamount>64.92</totalamount>
    <tax>4.95</tax>
    <date>Wed Nov 15 13:45:28 EST 2006</date>
</header>
<customerdetails>
    <username>user1</username>
    <name>
        <firstname>Harry</firstname>
        <lastname>Fletcher</lastname>
    </name>
    <state>South Dakota</state>
</customerdetails>
<orderitem>
    <position>1</position>
    <quantity>1</quantity>
    <productid>364</productid>
    <title>The 40YearOld</title>
    <price>29.98</price>
</orderitem>
<orderitem>
    <position>2</position>
    <quantity>1</quantity>
    <productid>299</productid>
    <title>Pulp Fiction</title>
    <price>29.99</price>
</orderitem>

【问题讨论】:

    标签: xslt namespaces freemarker


    【解决方案1】:

    为了防止自动转义:${Order.orderitem.@@markup?no_esc}。 (不幸的是,XML 包装方式早于自动转义,所以它一直保持这样......)

    防止重复xmlns-es...你不能。问题是orderitem-s 就@@markup 所知没有共同祖先,而共同的xmlns 可以解决这个问题,所以它是最安全的。

    【讨论】:

      猜你喜欢
      • 2021-11-18
      • 2011-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-27
      • 2023-04-11
      • 2014-04-14
      • 1970-01-01
      相关资源
      最近更新 更多