Xml XSLT复杂副本

Xml XSLT复杂副本,xml,xslt,Xml,Xslt,我想用XSL表复制一个XML文件。通过复制,我希望将XML文件“匿名化”,将XML的某些元素作为变量 基数: 2. 45 马丁 斜纹棉布 布拉布拉 11222 98 杜邦 伊夫 波波波 33450 结果: 2. 45 人45 让11267 布拉布拉 20045 98 人民98 伊夫33548 波波波 20098 我真正的XML文件显然更复杂。 编辑: 我不想要像这样的XSL: 或 我有很多处理工作要做,并且在几个层次上有一个复杂的文件。这将是难以管理的 Thank’s学习XSLT

我想用XSL表复制一个XML文件。通过复制,我希望将XML文件“匿名化”,将XML的某些元素作为变量

基数:


2.
45
马丁
斜纹棉布
布拉布拉
11222
98
杜邦
伊夫
波波波
33450
结果:


2.
45
人45
让11267
布拉布拉
20045
98
人民98
伊夫33548
波波波
20098
我真正的XML文件显然更复杂。

编辑: 我不想要像这样的XSL:


我有很多处理工作要做,并且在几个层次上有一个复杂的文件。这将是难以管理的


Thank’s

学习XSLT后,您会发现它实际上并不复杂。首先要做的是

就这样!尝试以下XSLT:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:output method="xml" indent="yes" />

    <xsl:template match="people/name">
        <xsl:copy>
            <xsl:value-of select="concat('people ', ../id)" />
        </xsl:copy>
    </xsl:template>

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

如果要更改任何其他字段,可以以类似的方式添加其他模板

编辑:如果您想让它更通用一点,而不是为每个字段设置模板,您可以这样做:

    <xsl:template match="people/*[not(self::id)]">
        <xsl:copy>
            <xsl:value-of select="concat(local-name(), ' ', ../id)" />
        </xsl:copy>
    </xsl:template>


这将匿名化
people
记录下的所有字段,除了id

“将XML的某些元素作为变量”之外,这并不意味着什么。变量可以在XSL转换期间使用。当转换结束时,变量就不存在了。您能解释一下为什么不想要您所展示的XSLT吗?谢谢。我有很多处理工作要做,还有一个复杂的文件在几个层次上。这将是难以管理的。谢谢。但我的文件更复杂。我不为每个文件使用一个简单的id。你能编辑你的问题来解释你想要实现的目标背后的逻辑吗?你想实施什么规则?例如,
{xyx/cp+id}
在输出中表示什么?谢谢,谢谢。完成。我的问题只是一个例子。我的文件比较复杂
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>
<xsl:template match="people/name">
    <xsl:copy>
        <xsl:value-of select="concat('people ', ../id)" />
    </xsl:copy>
</xsl:template>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:output method="xml" indent="yes" />

    <xsl:template match="people/name">
        <xsl:copy>
            <xsl:value-of select="concat('people ', ../id)" />
        </xsl:copy>
    </xsl:template>

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>
    <xsl:template match="people/*[not(self::id)]">
        <xsl:copy>
            <xsl:value-of select="concat(local-name(), ' ', ../id)" />
        </xsl:copy>
    </xsl:template>