我輸入的是:重命名和發送基於在子節點元素的值的所有子節點XSLT
<Recordset>
<Report_ID>
<Record>
<Report_ID>A1</Report_ID>
<name1>a1</name1>
<name2>a1</name2>
<name3>a1</name3>
<name4>true</name4>
</Record>
<Record>
<Report_ID>A1</Report_ID>
<name1>a1</name1>
<name2>b1</name2>
<name3>t1</name3>
<name4>false</name4>
</Record>
<Record>
<Report_ID>A1</Report_ID>
<name1>a1</name1>
<name2>a1</name2>
<name3>a1</name3>
<name4>false</name4>
</Record>
</Report_ID>
<Report_ID>
<Record>
<Report_ID>B1</Report_ID>
<name1>a1</name1>
<name2>a1</name2>
<name3>a1</name3>
<name4>true</name4>
</Record>
<Record>
<Report_ID>B1</Report_ID>
<name1>a1</name1>
<name2>a1</name2>
<name3>a1</name3>
<name4>true</name4>
</Record>
</Report_ID>
</Recordset>
起初我有一個下REPORT_ID,我已經通過獨特的REPORT_ID分組的多條記錄。接下來,我想實現以下目標:
目標:如果在一個Report_ID中,name4中的任何一個爲「false」,則該Report_Id下的所有記錄都應該去,並且父節點應重命名爲Report_ID_Complicated,如果所有name4值都爲true那麼它應該重命名爲Report_ID_Simple。分組很好...必須有另一個檢查條件,並且相應地重命名父節點。
<Recordset>
<Report_ID_Complicated>
<Record>
<Report_ID>A1</Report_ID>
<name1>a1</name1>
<name2>a1</name2>
<name3>a1</name3>
<name4>true</name4>
</Record>
<Record>
<Report_ID>A1</Report_ID>
<name1>a1</name1>
<name2>b1</name2>
<name3>t1</name3>
<name4>false</name4>
</Record>
<Record>
<Report_ID>A1</Report_ID>
<name1>a1</name1>
<name2>a1</name2>
<name3>a1</name3>
<name4>false</name4>
</Record>
</Report_ID_Complicated>
<Report_ID_Simple>
<Record>
<Report_ID>B1</Report_ID>
<name1>a1</name1>
<name2>a1</name2>
<name3>a1</name3>
<name4>true</name4>
</Record>
<Record>
<Report_ID>B1</Report_ID>
<name1>a1</name1>
<name2>a1</name2>
<name3>a1</name3>
<name4>true</name4>
</Record>
</Report_ID_Simple>
</Recordset>
UPDATE:
蒂姆的答案的作品完美,但我寫的波紋管代碼組的報告ID現在,當我試圖用我以前的代碼合併添的回答我得到「一個XSTL - 每個元素不得包含xsl:template元素「
我相信我們不能在每個模板中應用模板,所以如果你能指出我正確的方向,可以合併這兩個代碼。
我的XSLT代碼:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="kReport_Id" match="Record" use="Report_Id"/>
<xsl:key name="kname4" match="Record" use="concat(Report_Id,name4)"/>
<xsl:template match="/">
<ns:File_Intermediate>
<xsl:for-each select="ns:File/RecordSet/Record[generate-id() = generate-id(key('kReport_Id',Report_Id))]">
<Report_Id>
<ReportID_Simple>
<xsl:variable name="vReport_Id" select="Report_Id"/>
<xsl:for-each select="../Record[Report_Id = $vReport_Id][generate-id() = generate-id(key('kname4',concat(Report_Id,name4)))]">
<xsl:for-each select="../Record[Report_Id = $vReport_Id][name4=current()/name4]">
<xsl:variable name="name4" select="name4"/>
<xsl:if test="name4='true'">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</ReportID_Simple>
<ReportID_Complicated>
<xsl:variable name="vReport_Id" select="Report_Id"/>
<xsl:for-each select="../Record[Report_Id = $vReport_Id][generate-id() = generate-id(key('kname4',concat(Report_Id,name4)))]">
<xsl:for-each select="../Record[Report_Id = $vReport_Id][name4=current()/name4]">
<xsl:variable name="name4" select="name4"/>
<xsl:if test="name4='false'">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</ReportID_Complicated>
</Report_Id>
</xsl:for-each>
</ns:File_Intermediate>
</xsl:template>
</xsl:stylesheet>
您是否嘗試過的東西?你的XSLT在哪裏? – 2014-11-22 12:31:20