如何通过它的属性名称值复制xml标记

时间:2018-04-18 09:58:05

标签: java xml xslt

我有这样的xml:

kubectl apply -f

我想写一些XSLT,它将帮助我复制wsdata 另一个xml中的WSName PersonData,我应该如何管理呢?

2 个答案:

答案 0 :(得分:2)

您想要的表达式是//WSData[@WSName='Standard'],您可以在xsl:apply-templatesxsl:copy-of中的select子句中使用该表达式...

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

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

  <xsl:template match="/">
    <xsl:copy-of select="//WSData[@WSName='PersonData']" />
  </xsl:template>

</xsl:stylesheet>

答案 1 :(得分:1)

为实现此目的,您可以使用xsl:copy-of。请参阅以下链接或代码:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:output method="html" encoding="UTF-8" indent="yes" />

    <xsl:template match="/">
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="Job">
        <Job>
            <xsl:copy-of select="//WSData[@WSName='PersonData']"/>
        </Job>
    </xsl:template>

</xsl:transform>
相关问题