【问题标题】:Need to split the parent and child element into two seperate element需要将父子元素拆分成两个独立的元素
【发布时间】:2019-09-10 09:56:05
【问题描述】:

您好,我有以下输入 xml 文件:

<Description>Same Date <Text>True</Text></Description>

我尝试过的 XSL

<xsl:template match="Description">
    <def>
        <para>
            <title>
                <xsl:value-of select="Description"/>
            </title>
            <para>
                <xsl:value-of select="Text"/>
            </para>
        </para>
    </def>
</xsl:template>

预期输出:

<def>
    <para>
        <title>Same Date</title>
        <para>True</para>
    </para>
 </def>

我需要将子元素拆分成单独的元素。

【问题讨论】:

    标签: xslt xslt-2.0


    【解决方案1】:

    你可以试试这个:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        exclude-result-prefixes="xs"
        version="2.0">
        <xsl:output method="xml" omit-xml-declaration="no"/>
        <xsl:template match="Description">
            <def>
                <para>
                    <title>
                        <xsl:value-of select="normalize-space(node()[1])"/>
                    </title>
                    <xsl:if test="Text">
                        <para>
                            <xsl:value-of select="Text"/>
                        </para>
                    </xsl:if>
                </para>
            </def>
        </xsl:template>
    </xsl:stylesheet>
    

    【讨论】:

      【解决方案2】:

      更改以下代码:-

      <title><xsl:value-of select="Description"/></title>
      

      <title><xsl:value-of select="normalize-space(substring-before(., Text))"/></title>
      

      【讨论】:

      • 我在转换A sequence of more than one item is not allowed as the second argument of substring-before()时遇到这个错误
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-25
      • 2018-12-20
      • 1970-01-01
      • 1970-01-01
      • 2016-09-15
      • 2021-03-21
      • 1970-01-01
      相关资源
      最近更新 更多