我的xml输出结构如下:
<dataroot>
<Sessions>
<Session>
<SessionId>LLWNA181_3</SessionId>
<CaseId>KIFLLW</CaseId>
<SessionDate>2018-07-05T00:00:00</SessionDate>
<ServiceTypeId>13</ServiceTypeId>
<TotalNumberOfUnidentifiedClients>0</TotalNumberOfUnidentifiedClients>
<SessionClients>
<SessionClient>
<ClientId>LLWNA</ClientId>
<ParticipationCode>Client</ParticipationCode>
</SessionClient>
</SessionClients>
</Session>
</Sessions>
<Sessions>
<Session>
<SessionId>LLWNA181_4</SessionId>
<CaseId>KIFLLW</CaseId>
<SessionDate>2018-07-05T00:00:00</SessionDate>
<ServiceTypeId>8</ServiceTypeId>
<TotalNumberOfUnidentifiedClients>0</TotalNumberOfUnidentifiedClients>
<SessionClients>
<SessionClient>
<ClientId>LLWNA</ClientId>
<ParticipationCode>Client</ParticipationCode>
</SessionClient>
</SessionClients>
</Session>
</Sessions>
</dataroot>
仅需在“数据根”下面将会话作为第二级别,并且不需要与每个“会话”一起出现。 我想知道要转换此格式需要什么XSLT 1.0?
答案 0 :(得分:0)
在 XSLT 1.0 中,您可以尝试
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Sessions[preceding-sibling::*[1][self::Sessions]]"/>
<xsl:template match="Sessions">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
<xsl:if test="following-sibling::*[1][self::Sessions]">
<xsl:call-template name="wrapdata">
<xsl:with-param name="data" select="following-sibling::*[1][self::Sessions]"/>
</xsl:call-template>
</xsl:if>
</xsl:copy>
</xsl:template>
<xsl:template name="wrapdata">
<xsl:param name="data"/>
<xsl:copy-of select="$data/*"/>
<xsl:if test="$data/following-sibling::*[1][self::Sessions]">
<xsl:call-template name="wrapdata">
<xsl:with-param name="data" select="$data/following-sibling::*[1][self::Sessions]"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
看到转化