HI所有模板內的屬性,如何使用,如果條件(或者)在XSLT
如何使用,如果條件的屬性時,其每次循環打印不同的值。 我有一個名爲「AttributeName」的屬性。當每次循環時(總共5次),這將採用不同的名稱。
我嘗試了一些東西..但它沒有工作。我的輸入XML將不會有任何數據。我所要做的就是每次循環進行5次時打印不同的值。
輸入XML:
<?xml version="1.0" encoding="UTF-8"?>
</Solution>
<Solution>
<ID>22060000000000000000000002</ID>
<Title>ABCD</Title>
<Observations>
<Observation>DEF</Observation>
</Observations>
<ProblemDescription> 1234</ProblemDescription>
<ProblemCause>ADDD</ProblemCause>
<RepairProcedures>
<RepairProcedure>XYZ</RepairProcedure>
</RepairProcedures>
<ScenarioExplanation>
<Scenario>JIJIJIJIJI</Scenario>
<Scenario>SCENARIO1.</Scenario>
</ScenarioExplanation>
<DocumentReferences>
<DocRef>NO DATA</DocRef>
</DocumentReferences>
</Solution>
</Solutions>
XSLT:
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:stylesheet><xsl:template>
<xsl:element name="Tables">
<!-- Tables code here -->
</xsl:element>
<xsl:element name="Relationships">
<xsl:for-each select="Solutions/Solution">
<xsl:if test="RepairProcedures/RepairProcedure!= '' ">
<xsl:for-each select="RepairProcedures/RepairProcedure">
<xsl:variable name="vNumCols" select="5"/>
<xsl:element name="Relationship">
<xsl:for-each select="position() < vNumCols">
<xsl:attribute name="Action"><xsl:value-of select="'Insert'"/></xsl:attribute>
<xsl:attribute name="DestinationKey"><xsl:value-of select="1"/></xsl:attribute>
<xsl:attribute name="RelationshipSpec"><xsl:value-of select="'TableName'"/></xsl:attribute>
<xsl:attribute name="SourceKey"><xsl:value-of select="1"/></xsl:attribute>
<xsl:attribute name="RelCommonKey"><xsl:value-of select="1"/></xsl:attribute>
<xsl:attribute name="AttributeName">
<xsl:if test="position() = 1"><xsl:value-of select="CPComments"/></xsl:if>
<xsl:if test="position() = 2"><xsl:value-of select="CPConflict"/></xsl:if>
</xsl:attribute>
<xsl:attribute name="AttributeValue"><xsl:value-of select="1"/></xsl:attribute>
</xsl:for-each>
</xsl:element>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
我通過repairprocedures循環/ repairprocedure是讓 「RelationshipSpec」 文本。
預期輸出
<Relationships>
<Relationship Action="Delete" DestinationKey="1" RelationshipSpec="XYZ" SourceKey="2" RelCommonKey="1_2" AttributeName="CPComments" AttributeValue=""/>
<Relationship Action="Delete" DestinationKey="1" RelationshipSpec="XYZ" SourceKey="2" RelCommonKey="1_2" AttributeName="CPConflict" AttributeValue=""/>
<Relationship Action="Delete" DestinationKey="1" RelationshipSpec="XYZ" SourceKey="2" RelCommonKey="1_2" AttributeName="CPUserID" AttributeValue=""/>
<Relationship Action="Delete" DestinationKey="1" RelationshipSpec="XYZ" SourceKey="2" RelCommonKey="1_2" AttributeName="ProcessID" AttributeValue=""/>
<Relationship Action="Delete" DestinationKey="1" RelationshipSpec="XYZ" SourceKey="2" RelCommonKey="1_2" AttributeName="ProductId" AttributeValue=""/>
</Relationships>
在這些5行變化的唯一值是 「的AttributeName」。我試圖打印5行與AttributeName是不同的一個關係。
請幫我做這件事。
我使用XSLT 1.0
謝謝 拉姆
如果您可以提供樣本輸入(您的xml樣本根本不包含任何屬性)以及您對該輸入的預期輸出,那麼對所有人來說都會更容易。 – qwerty 2011-04-15 05:25:48
@qwerty:我的輸入xml只是用於打印RepairProcedure Value。不會有任何屬性。我的o/p會有這個價值。我添加了xslt和expectedoutput。但它的替代空白。我認爲格式化問題。我嘗試了幾次,但不知道如何格式化xslt ..;( – Ramm 2011-04-15 05:38:09
您太多地使用。嘗試使用代替它。 –
TOUDIdel
2011-04-15 08:55:27