簡體   English   中英

如何使用 XSL 從父節點復制所有子節點

[英]how to copy all the child nodes from a parent node using XSL

以下是我的輸入:

<csv>
<row>
    <stuff>a</stuff>
    <more>1</more>
    <evenmore>123</evenmore>
    <roww>
        <other>1345</other>
       <other>13845</other>
    </roww>
</row>
</csv>

預期輸出:

 <roww>
        <other>1345</other>
       <other>13845</other>
    </roww>

誰能讓我知道如何用 XSL 做到這一點?

嗯,這只是為了匹配父節點並執行copy-of

<xsl:copy-of>元素創建當前節點的副本。

注意:命名空間節點、子節點和當前節點的屬性也會自動復制!

實現預期輸出的XSLT 1.0解決方案可以是:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="yes" />

<xsl:template match="/csv">
    <xsl:copy-of select="row/roww" />
</xsl:template>

</xsl:stylesheet>

https://xsltfiddle.liberty-development.net/bFN1y93

您可以使用 TreeOps 樹轉換可視化工具來實現這一點。 TreeOps( https://github.com/treeops/treeops ):

  1. 加載 XML

  2. 添加轉換 - 向上移動“row/roww/other”

  3. 添加轉換 - 上移“行/其他”

  4. 添加轉換 - 刪除“行”

輸入和結果轉換

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM