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

如果“LONDON good”重复了很多次,它只需要打印一次。但我们必须重复座位不喜欢“1A 1B 1C 1D 1F 2G 等等”。我使用 xslt2.0 并且我的输出类型是文本。事情是没有必要多次显示项目我尝试了很多..无法找出解决方案请帮帮我。

4

1 回答 1

0

IMO您的输入xml与所需的输出不对应(例如,只有一个伦敦的customervalue = good。但可能我不太了解您的需求。但是遵循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
于 2013-07-15T15:39:10.363 回答