【问题标题】:Two names in one element (XSLT)一个元素中的两个名称 (XSLT)
【发布时间】:2016-06-29 03:38:11
【问题描述】:

你好我再试一次,因为我找不到我的问题的答案......

我有这个 XML 输入

<Name> Name1, Name2</Name>

在 XML 输出中我需要得到这个

<NameOfFirstOne>Name1 </NameOfFirstOne>
 <NameOfSecondOne>Name2 </NameOfSecondOne>  

但如果我做 value of 我总是得到两个名字,但我只需要一个。那我能用它做什么呢?

【问题讨论】:

标签: xml xslt


【解决方案1】:

如果您有 XPath 3.1(即 XSLT 2.0),那么您可以使用 tokenize() 函数通过指定的分隔符字符串分割您的字符串:

<xsl:template match="Name">
    <xsl:variable name="names" select="tokenize(text(),', ')"/>
    <NameOfFirstOne>
        <xsl:value-of select="$names[1]"/>
    </NameOfFirstOne>
    <NameOfSecondOne>
        <xsl:value-of select="$names[2]"/>
    </NameOfSecondOne>
</xsl:template>

【讨论】:

    猜你喜欢
    • 2014-06-16
    • 1970-01-01
    • 2019-02-15
    • 1970-01-01
    • 2010-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多