1

私のXMLは次のようなものです:

<?xml version="1.0" encoding="utf-8"?>
<Rowsets DateCreated="2012-08-01T17:43:31" EndDate="2012-08-01T17:43:03" StartDate="2012-08-01T16:43:03" Version="12.0.12 Build(9)">
<Rowset>
    <Columns>
        <Column Description="FirstName" MaxRange="1" MinRange="0" Name="Plant" SQLDataType="12" SourceColumn="Plant"/>
        <Column Description="Lastname" MaxRange="1" MinRange="0" Name="Process" SQLDataType="12" SourceColumn="Process"/>
        <Column Description="BorninMonth" MaxRange="1" MinRange="0" Name="ScheduleStartTimestamp" SQLDataType="93" SourceColumn="ScheduleStartTimestamp"/>
        <Column Description="BorninWeek" MaxRange="1" MinRange="0" Name="PO" SQLDataType="4" SourceColumn="PO"/>
        <Column Description="Phone" MaxRange="1" MinRange="0" Name="EquipmentName" SQLDataType="-1" SourceColumn="EquipmentName"/>
    </Columns>
    <Row>
        <FirstName>Derek</FirstName>
        <Lastname>Shah</Lastname>
        <BorninMonth>1</BorninMonth>
        <BorninWeek>1</BorninWeek>
        <Phone>925</Phone>
    </Row>
    <Row>
        <FirstName>Michael</FirstName>
        <Lastname>Shah</Lastname>
        <BorninMonth>1</BorninMonth>
        <BorninWeek>2</BorninWeek>
        <Phone>925</Phone>
    </Row>
    <Row>
        <FirstName>Yang</FirstName>
        <Lastname>Patel</Lastname>
        <BorninMonth>1</BorninMonth>
        <BorninWeek>1</BorninWeek>
        <Phone>925</Phone>
    </Row>
    <Row>
        <FirstName>Bruke</FirstName>
        <Lastname>Shah</Lastname>
        <BorninMonth>1</BorninMonth>
        <BorninWeek>1</BorninWeek>
        <Phone>925</Phone>
    </Row>
    <Row>
        <FirstName>Maulik</FirstName>
        <Lastname>Shah</Lastname>
        <BorninMonth>2</BorninMonth>
        <BorninWeek>2</BorninWeek>
        <Phone>925</Phone>
    </Row>
    <Row>
        <FirstName>Montu</FirstName>
        <Lastname>Shah</Lastname>
        <BorninMonth>3</BorninMonth>
        <BorninWeek>1</BorninWeek>
        <Phone>925</Phone>
    </Row>
    <Row>
        <FirstName>CHintu</FirstName>
        <Lastname>Shah</Lastname>
        <BorninMonth>4</BorninMonth>
        <BorninWeek>1</BorninWeek>
        <Phone>925</Phone>
    </Row>
    <Row>
        <FirstName>Pintu</FirstName>
        <Lastname>Shah</Lastname>
        <BorninMonth>4</BorninMonth>
        <BorninWeek>1</BorninWeek>
        <Phone>925</Phone>
    </Row>
    <Row>
        <FirstName>Puppy</FirstName>
        <Lastname>Patel</Lastname>
        <BorninMonth>4</BorninMonth>
        <BorninWeek>1</BorninWeek>
        <Phone>925</Phone>
    </Row>
    <Row>
        <FirstName>Tommy</FirstName>
        <Lastname>Shah</Lastname>
        <BorninMonth>5</BorninMonth>
        <BorninWeek>1</BorninWeek>
        <Phone>925</Phone>
    </Row>
</Rowset>

ここで、1 か月目に生まれ、名前が Shah である人の数を調べたいと思います。同じく2月生まれで姓はシャー。月3で生まれ、姓はシャー。

したがって、出力 XML は次のようになります。

<?xml version="1.0" encoding="utf-8"?>
<Rowsets DateCreated="2012-08-01T17:43:31" EndDate="2012-08-01T17:43:03" StartDate="2012-08-01T16:43:03" Version="12.0.12 Build(9)">
<Rowset>
    <Columns>
        <Column Description="FirstName" MaxRange="1" MinRange="0" Name="Plant" SQLDataType="12" SourceColumn="Plant"/>
        <Column Description="Lastname" MaxRange="1" MinRange="0" Name="Process" SQLDataType="12" SourceColumn="Process"/>
        <Column Description="BorninMonth" MaxRange="1" MinRange="0" Name="ScheduleStartTimestamp" SQLDataType="93" SourceColumn="ScheduleStartTimestamp"/>
        <Column Description="BorninWeek" MaxRange="1" MinRange="0" Name="PO" SQLDataType="4" SourceColumn="PO"/>
        <Column Description="Phone" MaxRange="1" MinRange="0" Name="EquipmentName" SQLDataType="-1" SourceColumn="EquipmentName"/>
    </Columns>
    <Row>
        <FirstName>Derek</FirstName>
        <Lastname>Shah</Lastname>
        <BorninMonth>1</BorninMonth>
        <BorninWeek>1</BorninWeek>
        <Phone>925</Phone>
        <CountMonth>3</CountMonth>
    </Row>
    <Row>
        <FirstName>Michael</FirstName>
        <Lastname>Shah</Lastname>
        <BorninMonth>1</BorninMonth>
        <BorninWeek>2</BorninWeek>
        <Phone>925</Phone>
        <CountMonth>3</CountMonth>
    </Row>
    <Row>
        <FirstName>Yang</FirstName>
        <Lastname>Patel</Lastname>
        <BorninMonth>1</BorninMonth>
        <BorninWeek>1</BorninWeek>
        <Phone>925</Phone>
        <CountMonth>3</CountMonth>
    </Row>
    <Row>
        <FirstName>Bruke</FirstName>
        <Lastname>Shah</Lastname>
        <BorninMonth>1</BorninMonth>
        <BorninWeek>1</BorninWeek>
        <Phone>925</Phone>
        <CountMonth>3</CountMonth>
    </Row>
    <Row>
        <FirstName>Maulik</FirstName>
        <Lastname>Shah</Lastname>
        <BorninMonth>2</BorninMonth>
        <BorninWeek>2</BorninWeek>
        <Phone>925</Phone>
        <CountMonth>1</CountMonth>
    </Row>
    <Row>
        <FirstName>Montu</FirstName>
        <Lastname>Shah</Lastname>
        <BorninMonth>3</BorninMonth>
        <BorninWeek>1</BorninWeek>
        <Phone>925</Phone>
        <CountMonth>1</CountMonth>
    </Row>
    <Row>
        <FirstName>CHintu</FirstName>
        <Lastname>Shah</Lastname>
        <BorninMonth>4</BorninMonth>
        <BorninWeek>1</BorninWeek>
        <Phone>925</Phone>
        <CountMonth>2</CountMonth>
    </Row>
    <Row>
        <FirstName>Pintu</FirstName>
        <Lastname>Shah</Lastname>
        <BorninMonth>4</BorninMonth>
        <BorninWeek>1</BorninWeek>
        <Phone>925</Phone>
        <CountMonth>2</CountMonth>
    </Row>
    <Row>
        <FirstName>Puppy</FirstName>
        <Lastname>Patel</Lastname>
        <BorninMonth>4</BorninMonth>
        <BorninWeek>1</BorninWeek>
        <Phone>925</Phone>
        <CountMonth>2</CountMonth>
    </Row>
    <Row>
        <FirstName>Tommy</FirstName>
        <Lastname>Shah</Lastname>
        <BorninMonth>5</BorninMonth>
        <BorninWeek>1</BorninWeek>
        <Phone>925</Phone>
        <CountMonth>1</CountMonth>
    </Row>
</Rowset>

そのため、Month の値をインクリメントして行数をカウントするような XML を作成するには、助けが必要です。

4

2 に答える 2

1

この変換:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text"/>
 <xsl:strip-space elements="*"/>

 <xsl:key name="kRowByNameMonth" match="Row"
  use="concat(Lastname, '+', BorninMonth)"/>

 <xsl:template match=
  "Row[Lastname='Shah']
      [generate-id()
      = generate-id(key('kRowByNameMonth',concat('Shah+',BorninMonth))[1])
      ]">
   Born in month: <xsl:value-of select="BorninMonth"/>
   <xsl:value-of select="concat(' Count: ',
                                count(key('kRowByNameMonth',
                                          concat('Shah+',BorninMonth)
                                          )
                                       )
                                )"/>
 </xsl:template>
 <xsl:template match="text()"/>
</xsl:stylesheet>

提供された XML ドキュメントに適用した場合:

    <Rowsets DateCreated="2012-08-01T17:43:31" EndDate="2012-08-01T17:43:03" StartDate="2012-08-01T16:43:03" Version="12.0.12 Build(9)">
    <Rowset>
        <Columns>
            <Column Description="FirstName" MaxRange="1" MinRange="0" Name="Plant" SQLDataType="12" SourceColumn="Plant"/>
            <Column Description="Lastname" MaxRange="1" MinRange="0" Name="Process" SQLDataType="12" SourceColumn="Process"/>
            <Column Description="BorninMonth" MaxRange="1" MinRange="0" Name="ScheduleStartTimestamp" SQLDataType="93" SourceColumn="ScheduleStartTimestamp"/>
            <Column Description="BorninWeek" MaxRange="1" MinRange="0" Name="PO" SQLDataType="4" SourceColumn="PO"/>
            <Column Description="Phone" MaxRange="1" MinRange="0" Name="EquipmentName" SQLDataType="-1" SourceColumn="EquipmentName"/>
        </Columns>
        <Row>
            <FirstName>Derek</FirstName>
            <Lastname>Shah</Lastname>
            <BorninMonth>1</BorninMonth>
            <BorninWeek>1</BorninWeek>
            <Phone>925</Phone>
        </Row>
        <Row>
            <FirstName>Michael</FirstName>
            <Lastname>Shah</Lastname>
            <BorninMonth>1</BorninMonth>
            <BorninWeek>2</BorninWeek>
            <Phone>925</Phone>
        </Row>
        <Row>
            <FirstName>Yang</FirstName>
            <Lastname>Patel</Lastname>
            <BorninMonth>1</BorninMonth>
            <BorninWeek>1</BorninWeek>
            <Phone>925</Phone>
        </Row>
        <Row>
            <FirstName>Bruke</FirstName>
            <Lastname>Shah</Lastname>
            <BorninMonth>1</BorninMonth>
            <BorninWeek>1</BorninWeek>
            <Phone>925</Phone>
        </Row>
        <Row>
            <FirstName>Maulik</FirstName>
            <Lastname>Shah</Lastname>
            <BorninMonth>2</BorninMonth>
            <BorninWeek>2</BorninWeek>
            <Phone>925</Phone>
        </Row>
        <Row>
            <FirstName>Montu</FirstName>
            <Lastname>Shah</Lastname>
            <BorninMonth>3</BorninMonth>
            <BorninWeek>1</BorninWeek>
            <Phone>925</Phone>
        </Row>
        <Row>
            <FirstName>CHintu</FirstName>
            <Lastname>Shah</Lastname>
            <BorninMonth>4</BorninMonth>
            <BorninWeek>1</BorninWeek>
            <Phone>925</Phone>
        </Row>
        <Row>
            <FirstName>Pintu</FirstName>
            <Lastname>Shah</Lastname>
            <BorninMonth>4</BorninMonth>
            <BorninWeek>1</BorninWeek>
            <Phone>925</Phone>
        </Row>
        <Row>
            <FirstName>Puppy</FirstName>
            <Lastname>Patel</Lastname>
            <BorninMonth>4</BorninMonth>
            <BorninWeek>1</BorninWeek>
            <Phone>925</Phone>
        </Row>
        <Row>
            <FirstName>Tommy</FirstName>
            <Lastname>Shah</Lastname>
            <BorninMonth>5</BorninMonth>
            <BorninWeek>1</BorninWeek>
            <Phone>925</Phone>
        </Row>
    </Rowset>
</Rowsets>

必要な正しい結果が生成されます

   Born in month: 1 Count: 3
   Born in month: 2 Count: 1
   Born in month: 3 Count: 1
   Born in month: 4 Count: 2
   Born in month: 5 Count: 1

説明:

複合キーを使用したMuenchian グループ化方法の適切な使用。

于 2012-08-10T01:37:59.757 に答える
0
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*" />

<xsl:template match="@*|node()">
 <xsl:copy>
  <xsl:apply-templates select="@*|node()"/>
 </xsl:copy>
</xsl:template>

<xsl:template match="Row">
 <xsl:copy>
  <xsl:apply-templates select="@*|node()"/>
  <CountMonth>
    <xsl:value-of select="count(../Row
      [BorninMonth = current()/BorninMonth]
      [Lastname    = current()/Lastname   ]    
       )" /> 
  </CountMonth> 
 </xsl:copy>
</xsl:template>

</xsl:stylesheet>
于 2012-08-10T01:03:14.160 に答える