XSLT:按类型将XML元素分组并输出为HTML表

XSLT:按类型将XML元素分组并输出为HTML表,xml,xslt,xslt-grouping,Xml,Xslt,Xslt Grouping,我有XML,其中包含描述对象的名称、值、sfid和FEILDSECATION的元素。对象按类型feildsection分组为providersection和DeviceType。 我的xml受到了打击 <RequestFields> <RequestField> <Name>Financial Change Type</Name> <Value>F/R Change (IRU to CRU)</Value> &

我有XML,其中包含描述对象的名称、值、sfid和FEILDSECATION的元素。对象按类型feildsection分组为providersection和DeviceType。 我的xml受到了打击

 <RequestFields>
<RequestField>
  <Name>Financial Change Type</Name>
  <Value>F/R Change (IRU to CRU)</Value>
  <sfid>Type</sfid>
  <feildsection>devicetype</feildsection>
</RequestField>
<RequestField>
  <Name>Service Number</Name>
  <Value>111-111-1111</Value>
  <sfid>00N30000000lTGp</sfid>
  <feildsection>serviceNo</feildsection>
</RequestField>
<RequestField>
  <Name>Confirm Service Number</Name>
  <Value>111-111-1111</Value>
</RequestField>
<RequestField>
  <Name>Device User</Name>
  <Value>Manager</Value>
  <sfid>00N30000000m6c7</sfid>
  <feildsection>ServiceNo</feildsection>
</RequestField>
<RequestField>
  <Name>Provider</Name>
  <Value>ATT</Value>
  <sfid>Provider__c</sfid>
  <feildsection>Deviceotype</feildsection>
</RequestField>
<RequestField>
  <Name>ExistingDeviceType</Name>
  <Value>BlackBerry</Value>
  <sfid>Current_Equipment_Type__c</sfid>
  <feildsection>devicetype</feildsection>
</RequestField>
<RequestField>
  <Name>Current Account Number</Name>
  <Value>I don't know this information</Value>
  <sfid>00N30000001BRgi</sfid>

</RequestField>
<RequestField hide="1">
  <Name>Current Password</Name>
  <Value>I don't know this information</Value>
  <sfid>Active_Profile_Password__c</sfid>
</RequestField>
<RequestField>
  <Name>Current Billing Name</Name>
  <Value>I don't know this information</Value>
</RequestField>
<RequestField>
  <Name>Current Billing Address</Name>
  <Value>I don'tknowthisinformation</Value>
</RequestField>
<RequestField>
  <Name>Manufacturer</Name>
  <Value></Value>
  <sfid>00N30000001BRm8</sfid>
  <feildsection>devicetype</feildsection>
</RequestField>
<RequestField>
  <Name>Model</Name>
  <Value></Value>
  <sfid>Activate_New_Equipment_Model__c</sfid>
</RequestField>
<RequestField>
  <Name>DeviceType</Name>
  <Value>BlackBerry</Value>
  <sfid>Equipment_Type__c</sfid>
</RequestField>

金融变化类型
F/R变更(IRU到CRU)
类型
设备类型
服务号码
111-111-1111
00N300000000LTGP
服务号
确认服务号码
111-111-1111
设备用户
经理
00N30000000m6c7
服务号
供应商
ATT
提供者
设备类型
现有设备类型
黑莓
当前设备类型c
设备类型
经常账户号码
我不知道这个信息
00N300000001BRGI
当前密码
我不知道这个信息
活动配置文件密码
当前帐单名称
我不知道这个信息
当前帐单地址
我不知道这个消息
制造商
00N300000001BRM8
设备类型
模型
激活新设备型号c
设备类型
黑莓
设备类型c

我想按feildsection类型对xml节点分组。我想查看我的输出 哪些节点的fieldsection值与一个节组中的值相同,如果节点没有feildsection,则最后显示Feild。请帮助找到解决方案

<table>
<tr>
<td colspan=2>Devicetype</td>
</tr>
<tr>
<td>Financial Change Type</td>
<td>F/R Change (IRU to CRU)<td>
</tr>
<tr>
<td>Provider</td>
<td>ATT<td>
</tr>
<tr>
<td>ExistingDeviceType</td>
<td>BlackBerry<td>
</tr>
<tr>
<td>Current Account Number</td>
<td>I don't know this information<td>
</tr>
<tr>
<td>Manufacturer</td>
<td></td>
</tr>
<tr>
<td colspan=2>serviceNo</td>
</tr>
<tr>
<td>Service Number</td>
<td>111-111-1111</td>
</tr>
<tr>
<td>Device User</td>
<td>Manager</td>
</tr>
<tr>
<td>Confirm Service Number</td>
<td>111-111-1111</td>
<td>Current Account Number</td>
<td>I don't know this information</td>
<td>Current Password</td>
<td>I don't know this information</td>
<td>Current Billing Name</td>
<td>I don't know this information</td>
<td>Current Billing Address</td>
<td>I don'tknowthisinformation</td>
<td>Model</td>
<td></td>`
</tr>
</table>

设备类型
金融变化类型
F/R变更(IRU到CRU)
供应商
ATT
现有设备类型
黑莓
经常账户号码
我不知道这个信息
制造商
服务号
服务号码
111-111-1111
设备用户
经理
确认服务号码
111-111-1111
经常账户号码
我不知道这个信息
当前密码
我不知道这个信息
当前帐单名称
我不知道这个信息
当前帐单地址
我不知道这个消息
模型
`

我不确定我是否在输出中得到了您想要的所有内容,但是如果您能够使用XSLT 2.0,下面的内容应该会对您有所帮助:

<xsl:template match="/RequestFields">
   <table>
   <!-- This is the grouping command avalaible in XSLT 2.0. Two things : 
        First you're only selecting field with 'feildsection' in their childs.
        Second, you use the group-by attribute to define youre grouping key (here the value of the feildsection child)-->
   <xsl:for-each-group select="*[feildsection]" group-by="feildsection">
          <!-- Here you could output the value of the grouping key with the below function 
          (current-grouping-key() only avalaible in a for-each-group context)-->
          <tr><td colspan='2'><xsl:value-of select="current-grouping-key()"/></td></tr>
          <xsl:apply-templates/>
   </xsl:for-each-group>
   <!-- At the end, you're dealing with element without feildsection -->
   <xsl:apply-templates select="*[not(feildsection)]"/>
   </table>
<xsl:template/>

<!-- here is the template for the RequestField element.-->
<xsl:template match="RequestField">
    <tr>
        <td><xsl:value-of select="Name"/></td>
        <td><xsl:value-of select="Value"/></td>
    </tr>
</xsl:template>


我遇到一个错误。关闭表的位置。可以在另一个tamplateYep中分配一个xsl:template,我的坏,忘记关闭元素。您可以在根模板内部关闭它,并在外部定义子模板。