2
我嘗試遍歷父節點的獨特子元素。框架預期的xml 下面是我的xml。動態獲取父元素並處理xml的動態子元素xslt
<NewDataSet>
<caseParticipants>
<Litigants>PORTFOLIO RECOVERY ASSOCIATES</Litigants>
<Attorneys>MANISCALCO, ANTHONY JOSEPH</Attorneys>
</caseParticipants>
<caseParticipants>
<Litigants>PLAINTIFF</Litigants>
<Attorneys>Plaintiff Attorney</Attorneys>
</caseParticipants>
<caseParticipants>
<Litigants />
<Attorneys />
<caseProceedings>
<Date>05/12/2015</Date>
<Details>PETITION/COMPLAINT NO DOC#</Details>
</caseProceedings>
<caseProceedings>
<Date>05/12/2015</Date>
<Details>ASM: SMALL CLAIMS $501-$2,500</Details>
</caseProceedings>
<caseCalendar>
<Date>06/30/2015 13:00:00</Date>
<Docket_x0020_Type>PRETRIAL CONF</Docket_x0020_Type>
<Judge>LANDT, ROBERT E</Judge>
<Location>XX : COURTR</Location>
</caseCalendar>
<caseFinancialSummary>
<Column1>Assessment Total:</Column1>
<Column2>$185.00</Column2>
</caseFinancialSummary>
<caseFinancialSummary>
<Column1>Assessment Paid:</Column1>
<Column2>$185.00</Column2>
</caseFinancialSummary>
<caseFinancialSummary>
<Column1>Assessment Due:</Column1>
<Column2>$0.00</Column2>
</caseFinancialSummary>
<caseFinancialSummary>
<Column1>Restitution Total:</Column1>
<Column2>$0.00</Column2>
</caseFinancialSummary>
<caseFinancialSummary>
<Column1>Restitution Paid:</Column1>
<Column2>$0.00</Column2>
</caseFinancialSummary>
<caseFinancialSummary>
<Column1>Restitution Due:</Column1>
<Column2>$0.00</Column2>
</caseFinancialSummary>
<caseFinancialSummary />
<caseFinancialdetails>
<Assessment_x0020_Due>$185.00</Assessment_x0020_Due>
<Assessment_x0020_Paid>$185.00</Assessment_x0020_Paid>
<Restitution_x0020_Due>$0.00</Restitution_x0020_Due>
<Restitution_x0020_Paid>$0.00</Restitution_x0020_Paid>
</caseFinancialdetails>
</NewDataSet>
我需要轉置爲像下面的XML。
<searchResult>
<caseDetails>
<caseParticipants Label="Participants">
<row>
<colhead id="1" align="left" bold="no">Litigants</colhead>
<colhead id="2" align="left" bold="no">Attorneys</colhead>
</row>
<row>
<cell id="1">Portfolio Recovery Associates</cell>
<cell id="2">Maniscalco, Anthony Joseph</cell>
</row>
<row>
<cell id="1">Plaintiff</cell>
<cell id="2">Plaintiff Attorney</cell>
</row>
<row>
<cell id="1" />
<cell id="2" />
</row>
</caseParticipants>
<caseProceedings Label="Proceedings">
<row>
<colhead id="1" align="left" bold="no">Date</colhead>
<colhead id="2" align="left" bold="no">Details</colhead>
</row>
<row>
<cell id="1">05/12/2015</cell>
<cell id="2">Petition/Complaint no Doc#</cell>
<document available="No" />
</row>
<row>
<cell id="1">05/12/2015</cell>
<cell id="2">Asm: Small Claims $501-$2,500</cell>
<document available="No" />
</row>
</caseProceedings>
<caseCalendar Label="Calendar">
<row>
<colhead id="1" align="left" bold="no">Date</colhead>
<colhead id="2" align="left" bold="no">Docket Type</colhead>
<colhead id="3" align="left" bold="no">Judge</colhead>
<colhead id="4" align="left" bold="no">Location</colhead>
<colhead id="5" align="left" bold="no">Prosecutor</colhead>
<colhead id="6" align="left" bold="no">Defendant Attorney</colhead>
</row>
<row>
<cell id="1">06/30/2015 13:00:00</cell>
<cell id="2">Pretrial Conf</cell>
<cell id="3">Landt, Robert E</cell>
<cell id="4">Xx : Courtr</cell>
<cell id="5" />
<cell id="6" />
</row>
</caseCalendar>
<caseFinancialSummary Label="Financial Summary">
<row>
<colhead id="1" align="right" bold="no" />
<colhead id="2" align="left" bold="no" />
</row>
<row>
<cell id="1">Assessment Total:</cell>
<cell id="2">$185.00</cell>
</row>
<row>
<cell id="1">Assessment Paid:</cell>
<cell id="2">$185.00</cell>
</row>
<row>
<cell id="1">Assessment Due:</cell>
<cell id="2">$0.00</cell>
</row>
<row>
<cell id="1">Restitution Total:</cell>
<cell id="2">$0.00</cell>
</row>
<row>
<cell id="1">Restitution Paid:</cell>
<cell id="2">$0.00</cell>
</row>
<row>
<cell id="1">Restitution Due:</cell>
<cell id="2">$0.00</cell>
</row>
</caseFinancialSummary>
<caseFinancialDetails Label="Financial Details">
<row>
<colhead id="1" align="left" bold="no">Assessment Due</colhead>
<colhead id="2" align="left" bold="no">Assessment Paid</colhead>
<colhead id="3" align="left" bold="no">Restitution Due</colhead>
<colhead id="4" align="left" bold="no">Restitution Paid</colhead>
<colhead id="5" align="left" bold="no">Payment Date</colhead>
</row>
<row>
<cell id="1">$185.00</cell>
<cell id="2">$185.00</cell>
<cell id="3">$0.00</cell>
<cell id="4">$0.00</cell>
<cell id="5" />
</row>
</caseFinancialDetails>
</caseDetails>
我想只有一個像下面caseParticipant部分。我需要爲所有節點這樣做,而不必提供元素名稱。因爲我每次都得到不同類型的父母和孩子的元素。
XSLT代碼:
<xsl:template match="caseParticipants">
<xsl:variable name="vrtfEvalResult">
<xsl:call-template name="eval">
<xsl:with-param name="pPath" select="'/NewDataSet/caseParticipants'"/>
</xsl:call-template>
</xsl:variable>
<row>
<cell id="1"><xsl:value-of select="Litigants" /></cell>
<cell id="2"><xsl:value-of select="Attorney" /></cell>
</row>
</xsl:template>
<xsl:template match="text()"/>
<xsl:template match="Path" name="eval">
<xsl:param name="pPath" select="."/>
<xsl:param name="pContext" select="/"/>
<xsl:choose>
<!-- If there is something to evaluate -->
<xsl:when test="string-length($pPath) >0">
<xsl:variable name="vPath" select=
"substring($pPath,2)"/>
<xsl:variable name="vNameTest">
<xsl:choose>
<xsl:when test="not(contains($vPath, '/'))">
<xsl:value-of select="$vPath"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select=
"substring-before($vPath, '/')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:call-template name="eval">
<xsl:with-param name="pPath" select=
"substring-after($pPath, $vNameTest)"/>
<xsl:with-param name="pContext" select=
"$pContext/*[name()=$vNameTest]"/>
</xsl:call-template>
</xsl:when>
<!-- Otherwise we have evaluated completely the path -->
<xsl:otherwise>
<xsl:copy-of select="$pContext"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
在此先感謝
非常感謝,這是我所期望的...... – Prabha
沒問題 - 我的經驗法則是,每當我想要一個「獨特」或XSLT「組」,再想想關於如何使用「鑰匙」去那裏 –
好的確定......感謝您的指導.. – Prabha