首页 > 解决方案 > 如何跳过第一个 xml 元素组(标题行)

问题描述

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

标签: xmlxsltxml-parsingxslt-2.0xslt-3.0

解决方案


对第一行使用空元素/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


推荐阅读