Tôi đã tạo XSLT và tôi đã tự hỏi làm thế nào có thể sao chép tất cả các nút giữa một bộ thẻ và thêm thẻ khác ở dưới cùng. Tôi đã tạo XSLT có tất cả các logic để xác định thẻ cần thêm và cái gì cần được gọi. Tuy nhiên vấn đề bây giờ tôi nhận được là tôi không thể sao chép tất cả các thẻ khác trên. Dưới đây là các tập tin trong câu hỏi:XSLT - Sao chép tất cả các nút khác, thêm 1 nút mới
XSLT
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/csvImportSchema">
<csvImportSchema>
<xsl:for-each select="payload">
<payload>
<xsl:copy-of select="@*"/>
<xsl:variable name="ean">
<xsl:value-of select="ean"/>
</xsl:variable>
<xsl:for-each select="../product">
<xsl:if test="ean = $ean">
<productId><xsl:value-of select="article"/></productId>
</xsl:if>
</xsl:for-each>
</payload>
</xsl:for-each>
</csvImportSchema>
</xsl:template>
</xsl:stylesheet>
ĐẦU VÀO
<?xml version="1.0" encoding="UTF-8"?>
<csvImportSchema>
<payload>
<test>1</test>
<test2>2</test2>
<test3>3</test3>
<ean>1111111111</ean>
<productId/>
</payload>
<product>
<article>722619</article>
<ean>1111111111</ean>
</product>
</csvImportSchema>
HIỆN OUTPUT
<?xml version="1.0" encoding="utf-8"?>
<csvImportSchema>
<payload>
<productId>722619</productId>
</payload>
</csvImportSchema>
MONG MUỐN OUTPUT
<?xml version="1.0" encoding="UTF-8"?>
<csvImportSchema>
<payload>
<test>1</test>
<test2>2</test2>
<test3>3</test3>
<ean>1111111111</ean>
<productId>722619</productId>
</payload>
</csvImportSchema>
Cảm ơn bạn. Tôi sẽ giữ cho rằng trong tâm trí. – MMKD