Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
XSLT 1.0-迭代删除文本开头的字符_Xslt_Xpath_Xslt 1.0 - Fatal编程技术网

XSLT 1.0-迭代删除文本开头的字符

XSLT 1.0-迭代删除文本开头的字符,xslt,xpath,xslt-1.0,Xslt,Xpath,Xslt 1.0,我有一个这样的xml(并且仅限于使用XSLT1.0来处理它) 某些模板 某物 名字 /独一无二的 someContextID 某些类人猿 /独一无二的 someContextID 某些类人猿 /独一无二的 someContextID 某些类人猿 我想删除关联/对象节点下ID节点中每个值开头的字符“/”。预期的输出应该是这样的 <Template> <ID>someTemplate</ID> <Object>

我有一个这样的xml(并且仅限于使用XSLT1.0来处理它)


某些模板
某物
名字
/独一无二的
someContextID
某些类人猿
/独一无二的
someContextID
某些类人猿
/独一无二的
someContextID
某些类人猿
我想删除关联/对象节点下ID节点中每个值开头的字符“/”。预期的输出应该是这样的

    <Template>
    <ID>someTemplate</ID>
    <Object>
        <ID>someID</ID>
        <Name>someName</Name>
        <Association type="someAssociation">
            <Object>
                <ID>someUniqueID</ID>
                <Context>
                    <ID>someContextID</ID>
                </Context>
                <ClassID>someClassID</ClassID>
            </Object>
        </Association>
        <Association type="someAssociation">
            <Object>
                <ID>someUniqueID</ID>
                <Context>
                    <ID>someContextID</ID>
                </Context>
                <ClassID>someClassID</ClassID>
            </Object>
        </Association>
        <Association type="someAssociation">
            <Object>
                <ID>someUniqueID</ID>
                <Context>
                    <ID>someContextID</ID>
                </Context>
                <ClassID>someClassID</ClassID>
            </Object>
        </Association>
    </Object>
</Template>

某些模板
某物
名字
独一无二的
someContextID
某些类人猿
独一无二的
someContextID
某些类人猿
独一无二的
someContextID
某些类人猿

我一直在研究translate()函数,但正在努力寻找实现它的方法。

编写一个模板,以斜杠开头匹配那些
ID
元素,然后简单地输出斜杠后面的值和子字符串:

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

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

<xsl:template match="ID[starts-with(., '/')]">
  <xsl:copy>
    <xsl:value-of select="substring(., 2)"/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>


如果只想处理这些特定的ID元素,您可能需要将匹配模式调整为
关联/Object/ID

非常优雅的解决方案,效果完美。非常感谢。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

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

<xsl:template match="ID[starts-with(., '/')]">
  <xsl:copy>
    <xsl:value-of select="substring(., 2)"/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>