基于三个字段的 XSLT2.0 分组


 <passengergroup>
     <passengerList>
<passDetails>
    <route>LONDON</route>
    <lastname>RAY</lastname>
</passDetails>
<seatDetails>
    <SeatNo>1A</SeatNo>
</seatDetails>
<customervalue>AB</customervalue>
   </passengerList
     <passengerList>
<passDetails>
    <route>LONDON</route>
    <lastname>RAY</lastname>
</passDetails>
<seatDetails>
    <SeatNo>1B</SeatNo>
</seatDetails>
<customervalue>good</customervalue>
     </passengerList
<passengerList>
  <passDetails>
          <route>DELHI</route>
   <lastname>RAY</lastname>
  </passDetails>
        <seatDetails>
     <SeatNo>2C</SeatNo>
   </seatDetails>
   <customervalue>BC</customervalue>
         </passengerList>
         <passengerList>
    <passDetails>
    <route>DELHI</route>
     <lastname>RAY</lastname>
    </passDetails>
    <seatDetails>
        <SeatNo>2D</SeatNo>
    </seatDetails>
    <customervalue>okey</customervalue>
       </passengerList>
   </passengergroup>

  <xsl:for-each select="passengergroup/passengerList">
<xsl:if test="customervalue='good'
    <xsl:value-of select="route"/><xsl:text> </xsl:text>
    <xsl:value-of select="customervalue"/><xsl:text> </xsl:text>
    <xsl:value-of select="seatDetails/SeatNo"/>
  </for-each>
  <xsl:for-each select="passengergroup/passengerList">
        <xsl:if test="customervalue='ok'
<xsl:value-of select="route"/><xsl:text> </xsl:text>
<xsl:value-of select="customervalue"/><xsl:text> </xsl:text>
<xsl:value-of select="seatDetails/SeatNo"/>
   </for-each>
  Output
   It will produce output like this
   LONDON good 1A
   LONDON good 1B
   DELHI okey 2C
   DELHI okey 2D
      But i need the output like this 
  LONDON good 1A 1B
  DELHI okey 2C 2D

如果"伦敦好"重复了很多次,它只需要打印一次,但我们必须重复座位不像'1A 1B 1C 1D 1F 2G 等等'.我使用的是 xslt2.0,我的输出类型是文本。事情是不需要多次显示项目我尝试了很多..无法找出解决方案,请帮助我。

IMO 您的输入 xml 与所需的输出不对应(例如,只有一个 LONDON,客户价值 = 好。但可能是我不太明白你需要什么。但是遵循xslt可以做一份工作。

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
    <xsl:output method="text" />
    <xsl:template match="/">
            <xsl:apply-templates select="passengergroup" />
    </xsl:template>
    <xsl:template match="passengergroup">
        <xsl:for-each-group select="passengerList" group-by="concat(passDetails/route, ' ', customervalue)">
            <xsl:value-of select="current-grouping-key()" />
            <xsl:text> </xsl:text>
            <xsl:value-of select="current-group()/seatDetails/SeatNo" separator=" " />
            <xsl:value-of select="'&#10;'" />
        </xsl:for-each-group>
    </xsl:template>
</xsl:stylesheet>

对于输入

<?xml version="1.0" encoding="UTF-8"?>
<passengergroup>
    <passengerList>
        <passDetails>
            <route>LONDON</route>
            <lastname>RAY</lastname>
        </passDetails>
        <seatDetails>
            <SeatNo>1A</SeatNo>
        </seatDetails>
        <customervalue>good</customervalue>
    </passengerList>
    <passengerList>
        <passDetails>
            <route>LONDON</route>
            <lastname>RAY</lastname>
        </passDetails>
        <seatDetails>
            <SeatNo>1B</SeatNo>
        </seatDetails>
        <customervalue>good</customervalue>
    </passengerList>
    <passengerList>
        <passDetails>
            <route>DELHI</route>
            <lastname>RAY</lastname>
        </passDetails>
        <seatDetails>
            <SeatNo>2C</SeatNo>
        </seatDetails>
        <customervalue>BC</customervalue>
    </passengerList>
    <passengerList>
        <passDetails>
            <route>DELHI</route>
            <lastname>RAY</lastname>
        </passDetails>
        <seatDetails>
            <SeatNo>2D</SeatNo>
        </seatDetails>
        <customervalue>okey</customervalue>
    </passengerList>
</passengergroup>

它产生以下输出

LONDON good 1A 1B
DELHI BC 2C
DELHI okey 2D

相关内容

  • 没有找到相关文章

最新更新