【问题标题】:How to skip first xml element group (Header Row)如何跳过第一个 xml 元素组(标题行)
【发布时间】:2019-02-01 19:55:25
【问题描述】:

下面是我下面的 XML sn-p 。我在第一组中收到完整的标题,我的数据从病房的第二个元素组开始。在这里我怎样才能跳过第一组?就像我需要避免第一行元素并需要从第二行元素中使用。一些身体可以发光,我如何通过 XSLT 实现这一点?

<?xml version='1.0' encoding='UTF-8'?>
<root>
<row>
    <Empl-Id>Empl Id</Empl-Id>
    <Company>Company</Company>
    <firstname>firstname</firstname>
    <lastname>lastname</lastname>
    <Goal-Amount>Goal Amount</Goal-Amount>  
</row>
<row>
    <Empl-Id>0111</Empl-Id>
    <Company>A11</Company>
    <firstname>Jumn</firstname>
    <lastname>Henrry</lastname>
    <Goal-Amount>100</Goal-Amount>  
</row>
<row>
    <Empl-Id>0112</Empl-Id>
    <Company>A12</Company>
    <firstname>Jumn2</firstname>
    <lastname>Henrry2</lastname>
    <Goal-Amount>120t</Goal-Amount> 
</row>

【问题讨论】:

    标签: xml xslt xml-parsing xslt-2.0 xslt-3.0


    【解决方案1】:

    第一行使用空元素/root/row[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 indent="yes"/>
    
        <xsl:template match="@* | node()">
            <xsl:copy>
                <xsl:apply-templates select="@* | node()"/>
            </xsl:copy>
        </xsl:template>
    
        <xsl:template match="/root/row[1]"/>
    
    </xsl:stylesheet>
    

    您的输出如下:

    <?xml version="1.0" encoding="UTF-8"?>
    <root>
    
        <row>
            <Empl-Id>0111</Empl-Id>
            <Company>A11</Company>
            <firstname>Jumn</firstname>
            <lastname>Henrry</lastname>
            <Goal-Amount>100</Goal-Amount>  
        </row>
        <row>
            <Empl-Id>0112</Empl-Id>
            <Company>A12</Company>
            <firstname>Jumn2</firstname>
            <lastname>Henrry2</lastname>
            <Goal-Amount>120t</Goal-Amount> 
        </row>
    </root>
    

    参见提到的链接: https://xsltfiddle.liberty-development.net/6qVRKww

    【讨论】:

      【解决方案2】:

      如果您选择或处理/root/row[position() gt 1],则仅选择或处理从第二个位置开始的row 元素。 tail(/root/row)subsequence(/root/row, 2) 或 XPath 中的其他选项。

      在 XSLT 的上下文中,根据剩余 XSLT 的外观,使用空模板 &lt;xsl:template match="root/row[1]"/&gt; 以确保第一个 row 不会产生任何输出也可能就足够了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-10-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-01-08
        • 2015-10-25
        • 1970-01-01
        相关资源
        最近更新 更多