更新属性名称和元素值



我需要将地址行 1 和里面的值更新为 1 简位并将其保存在变量中。输入是任何虚拟的 xml

使用此样式表

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xsl:template match="/">
        <xsl:variable name="request">
            <customers>
                <customer name="Address">1 Doe Place</customer>
                <customer name="State">OH</customer>
                <customer name="Name">John</customer>
                <customer name="Name">Kevin</customer>
                <customer name="Name">Leon</customer>
                <customer name="Name">Adam</customer>
                <customer name="city">Columbus</customer>
            </customers>
        </xsl:variable>
        <xsl:variable name="response">
        -------
        </xsl:variable>
        <xsl:copy-of select="$response"/>
    </xsl:template>
</xsl:stylesheet>

不知道这里到底要更新什么。我知道如何处理身份转换,但在这里我很困惑

也许这样的事情可以为你工作(我仍然对这到底是什么感到困惑):

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:variable name="request">
    <customers>
        <customer name="Address">1 Doe Place</customer>
        <customer name="State">OH</customer>
        <customer name="Name">John</customer>
        <customer name="Name">Kevin</customer>
        <customer name="Name">Leon</customer>
        <customer name="Name">Adam</customer>
        <customer name="city">Columbus</customer>
    </customers>
</xsl:variable>
<xsl:variable name="response">
    <customers>
        <xsl:for-each select="exsl:node-set($request)/customers/customer">
            <xsl:choose>
                <xsl:when test="@name='Address'">
                    <xsl:copy>
                        <xsl:copy-of select="@*"/>
                        <xsl:text>1 Jane place</xsl:text>
                    </xsl:copy>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:copy-of select="."/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:for-each>
    </customers>
</xsl:variable>
<xsl:template match="/">
    <xsl:copy-of select="$response"/>
</xsl:template>
</xsl:stylesheet>

应用于任何 XML 输入时的结果:

<?xml version="1.0" encoding="UTF-8"?>
<customers>
   <customer name="Address">1 Jane place</customer>
   <customer name="State">OH</customer>
   <customer name="Name">John</customer>
   <customer name="Name">Kevin</customer>
   <customer name="Name">Leon</customer>
   <customer name="Name">Adam</customer>
   <customer name="city">Columbus</customer>
</customers>

相关内容

  • 没有找到相关文章

最新更新