我有兩個假設條件XSLT,如下圖所示:動態條件執行XSLT
<xsl:if test="ns2:RoadPart/ns2:Vehicles/ns3:SemiVehicle>// for semi vehicle
//code to show values from XML(ie 20,20)
</xsl:if>
<xsl:if test="ns2:RoadPart/ns2:Vehicles/ns3:NonsemiVehicle>// for non-semivehicle
//code to show values from XML(ie 10,10)
</xsl:if>
我的XML如下:
// For Non semi vehicle
<RoutePart Id="374941">
<Vehicles>
<NonsemiVehicle>
<OverallLengthListPosition xmlns="http://www.esdal.com/schemas/core/vehicle">
<OverallLength>
<IncludingProjections>10</IncludingProjections>
<ExcludingProjections>10</ExcludingProjections>
</OverallLength>
</OverallLengthListPosition>
</NonsemiVehicle>
</Vehicles>
</RoutePart>
// For Semi vehicle
<RoutePart Id="374941">
<Vehicles>
<SemiVehicle>
<OverallLengthListPosition xmlns="http://www.esdal.com/schemas/core/vehicle">
<OverallLength>
<IncludingProjections>20</IncludingProjections>
<ExcludingProjections>20</ExcludingProjections>
</OverallLength>
</OverallLengthListPosition>
</SemiVehicle>
</Vehicles>
</RoutePart>
當我分析這個XSLT每次SemiVehicle列第一和非排名車輛排名第二。我每次都要按照給定的XML動態地調用它。
請幫助我。
編輯XSLT細節:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns1="http://test/schemas/core/proposedroute"
xmlns:ns2="http://test/schemas/core/movement"
xmlns:ns3="http://test/schemas/core/vehicle"
xmlns:ns4="http://test/schemas/core/commontypes"
xmlns:ns5="http://test/schemas/core/route"
xmlns:ns6="http://test/schemas/core/drivinginstruction"
xmlns:ns7="http://test/schemas/core/formattedtext"
xmlns:ns8="http://test/people/bs7666"
xmlns:ns9="http://test/schemas/core/annotation"
xmlns:ns10="http://test/schemas/core/caution"
xmlns:ns11="http://test/schemas/common/movementversion"
xmlns:ns12="http://test/schemas/core/contact">
<xsl:param name="Contact_ID"></xsl:param>
<xsl:param name="UnitType"></xsl:param>
<xsl:param name="DocType"></xsl:param>
<xsl:template match="/ns1:Proposal">
<html>
<body style="font-family:Arial;font-size:13px;">
<br/>
<b>Provisional Route</b>
<!--Change Code Start RM#4604 21 july-->
<xsl:variable name="FirstVehicle">
<xsl:for-each select="ns2:RouteParts/ns2:RoutePartListPosition/ns2:RoutePart/ns2:RoadPart/ns2:Vehicles">
<xsl:if test="ns3:ConfigurationSummaryListPosition/ns3:ConfigurationSummary != ''">
<xsl:if test="position()=1">
<xsl:choose>
<xsl:when test="contains(ns3:ConfigurationSummaryListPosition/ns3:ConfigurationSummary, '##**##')">
<xsl:value-of select="substring-after(ns3:ConfigurationSummaryListPosition/ns3:ConfigurationSummary,'##**##')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="ns3:ConfigurationSummaryListPosition/ns3:ConfigurationSummary"/>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="StatusVehicle">
<xsl:for-each select="ns2:RouteParts/ns2:RoutePartListPosition/ns2:RoutePart/ns2:RoadPart/ns2:Vehicles">
<xsl:if test="ns3:ConfigurationSummaryListPosition/ns3:ConfigurationSummary != ''">
<xsl:choose>
<xsl:when test="contains(ns3:ConfigurationSummaryListPosition/ns3:ConfigurationSummary, '##**##')">
<xsl:if test="$FirstVehicle != substring-after(ns3:ConfigurationSummaryListPosition/ns3:ConfigurationSummary,'##**##')">
<xsl:value-of select="false()"/>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:if test="$FirstVehicle != ns3:ConfigurationSummaryListPosition/ns3:ConfigurationSummary">
<xsl:value-of select="false()"/>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="CountVehicles">
<xsl:for-each select="ns2:RouteParts/ns2:RoutePartListPosition/ns2:RoutePart">
<xsl:if test="$UnitType=692001">
<xsl:if test="$StatusVehicle = 'false'">
<item>
Leg:
<xsl:choose>
<xsl:when test="contains(ns2:Name, '##**##')">
<xsl:value-of select="substring-after(ns2:Name, '##**##')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="ns2:Name" />
</xsl:otherwise>
</xsl:choose>
<xsl:text disable-output-escaping="yes"><![CDATA[ ]]></xsl:text>
<xsl:choose>
<!--Changes for RM#4998-->
<xsl:when test="contains(ns2:RoadPart/ns2:Distance/ns2:Metric/ns2:Distance, '##**##')">
<xsl:call-template name="SplitAlternative">
<xsl:with-param name="pText" select="substring-after(ns2:RoadPart/ns2:Distance/ns2:Metric/ns2:Distance, '##**##')"></xsl:with-param>
<xsl:with-param name="pDelim" select=" OR"></xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="SplitAlternative">
<xsl:with-param name="pText" select="ns2:RoadPart/ns2:Distance/ns2:Metric/ns2:Distance"></xsl:with-param>
<xsl:with-param name="pDelim" select=" OR"></xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</item>
</xsl:if>
</xsl:if>
<xsl:if test="$UnitType=692002">
<xsl:if test="$StatusVehicle = 'false'">
<item>
Leg:
<xsl:choose>
<xsl:when test="contains(ns2:Name, '##**##')">
<xsl:value-of select="substring-after(ns2:Name, '##**##')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="ns2:Name" />
</xsl:otherwise>
</xsl:choose>
<xsl:text disable-output-escaping="yes"><![CDATA[ ]]></xsl:text>
<xsl:choose>
<!--Changes for RM#4998-->
<xsl:when test="contains(ns2:RoadPart/ns2:Distance/ns2:Metric/ns2:Distance, '##**##')">
<xsl:call-template name="SplitAlternative">
<xsl:with-param name="pText" select="substring-after(ns2:RoadPart/ns2:Distance/ns2:Imperial/ns2:Distance, '##**##')"></xsl:with-param>
<xsl:with-param name="pDelim" select=" OR"></xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="SplitAlternative">
<xsl:with-param name="pText" select="ns2:RoadPart/ns2:Distance/ns2:Imperial/ns2:Distance"></xsl:with-param>
<xsl:with-param name="pDelim" select=" OR"></xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</item>
</xsl:if>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="VehiclesArray" select="msxsl:node-set($CountVehicles)/item" />
<!--Change Code End RM#4604 21 july-->
<!--For Semi Vehicles-->
<xsl:if test="ns2:RouteParts/ns2:RoutePartListPosition/ns2:RoutePart/ns2:RoadPart/ns2:Vehicles/ns3:VehicleSummaryListPosition/ns3:VehicleSummary/ns3:Configuration/ns3:SemiVehicle/ns3:Summary !=''">
<xsl:for-each select="ns2:RouteParts/ns2:RoutePartListPosition/ns2:RoutePart/ns2:RoadPart/ns2:Vehicles/ns3:VehicleSummaryListPosition/ns3:VehicleSummary/ns3:Configuration/ns3:SemiVehicle">
<xsl:variable name="getPosition" select="position()" />
<xsl:if test="$getPosition > 1">
<b>
<xsl:value-of select="$VehiclesArray[$getPosition]"/>
</b>
<br></br>
</xsl:if>
<br/>
<table style ="margin-left" border = "1">
<tr>
<td>
<b>
<!--TODO 1-->
Semi trailer
</b>
</td>
<td colspan="2">
<b>
<xsl:if test="ns3:Summary!='' ">
<xsl:value-of select="ns3:Summary"/>
</xsl:if>
</b>
</td>
</tr>
<!--</xsl:if >-->
<xsl:if test="ns3:GrossWeight/ns3:Weight!=''">
<tr>
<td>Gross weight:</td>
<td colspan="2">
<xsl:if test="ns3:GrossWeight/ns3:Weight!=''">
<xsl:choose>
<xsl:when test="contains(ns3:GrossWeight/ns3:Weight, '##**##')">
<xsl:value-of select="substring-after(ns3:GrossWeight/ns3:Weight, '##**##')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="ns3:GrossWeight/ns3:Weight"/>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="$UnitType='' or $UnitType=692001">
<xsl:text disable-output-escaping="yes"><![CDATA[ ]]></xsl:text>kg
</xsl:when>
<xsl:otherwise>
<xsl:text disable-output-escaping="yes"><![CDATA[ ]]></xsl:text>kg
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</td>
</tr>
</xsl:if>
<xsl:if test="ns3:AxleConfiguration/ns3:AxleWeightListPosition/ns3:AxleWeight !=''">
<tr>
<td>Axle weight:</td>
<td colspan="2">
<xsl:for-each select="ns3:AxleConfiguration/ns3:AxleWeightListPosition">
<xsl:if test="ns3:AxleWeight!='' and ns3:AxleWeight/@AxleCount!=''">
<xsl:choose>
<xsl:when test="contains(ns3:AxleWeight, '##**##')">
<xsl:value-of select="substring-after(ns3:AxleWeight, '##**##')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="ns3:AxleWeight"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text disable-output-escaping="yes"><![CDATA[ ]]></xsl:text>kg<xsl:text disable-output-escaping="yes"><![CDATA[ ]]></xsl:text> x<xsl:text disable-output-escaping="yes"><![CDATA[ ]]></xsl:text>
<xsl:choose>
<xsl:when test="contains(ns3:AxleWeight/@AxleCount, '##**##')">
<xsl:value-of select="substring-after(ns3:AxleWeight/@AxleCount, '##**##')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="ns3:AxleWeight/@AxleCount"/>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
<xsl:if test="position() != last()">
,
</xsl:if>
</xsl:for-each>
</td>
</tr>
</xsl:if>
</table>
<br/>
</xsl:for-each>
</xsl:if>
<!--For Semi Vehicles Ends here-->
<!--For Non Semi Vehicles-->
<xsl:if test="ns2:RouteParts/ns2:RoutePartListPosition/ns2:RoutePart/ns2:RoadPart/ns2:Vehicles/ns3:VehicleSummaryListPosition/ns3:VehicleSummary/ns3:Configuration/ns3:NonSemiVehicle/ns3:ComponentListPosition/ns3:Component/ns3:DrawbarTractor/ns3:Summary != ''
or ns2:RouteParts/ns2:RoutePartListPosition/ns2:RoutePart/ns2:RoadPart/ns2:Vehicles/ns3:VehicleSummaryListPosition/ns3:VehicleSummary/ns3:Configuration/ns3:NonSemiVehicle/ns3:ComponentListPosition/ns3:Component/ns3:LoadBearing/ns3:Summary != '' ">
<xsl:for-each select="ns2:RouteParts/ns2:RoutePartListPosition/ns2:RoutePart/ns2:RoadPart/ns2:Vehicles/ns3:VehicleSummaryListPosition/ns3:VehicleSummary/ns3:Configuration/ns3:NonSemiVehicle/ns3:ComponentListPosition">
<xsl:variable name="getPosition" select="position()" />
<xsl:if test="$getPosition > 1">
<b>
<xsl:value-of select="$VehiclesArray[$getPosition]"/>
</b>
<br></br>
</xsl:if>
<br></br>
<table style ="margin-left" border = "1">
<tr>
<td>
<b>
<!--TODO 1-->
<xsl:choose>
<xsl:when test="contains(ns3:Component, 'tractor')">
Tractor
</xsl:when>
<xsl:when test="contains(ns3:Component, 'trailer')">
Trailer
</xsl:when>
<xsl:when test="contains(ns3:Component, 'spmt')">
SPMT
</xsl:when>
<xsl:otherwise>
Tractor
</xsl:otherwise>
</xsl:choose>
</b>
</td>
<td colspan="2">
<b>
<xsl:if test="contains(ns3:Component/ns3:DrawbarTractor/ns3:Summary, '##**##')=false()">
<xsl:value-of select="ns3:Component/ns3:DrawbarTractor/ns3:Summary"/>
</xsl:if>
<xsl:if test="contains(ns3:Component/ns3:DrawbarTractor/ns3:Summary, '##**##')=true()">
<xsl:value-of select="substring-after(ns3:Component/ns3:DrawbarTractor/ns3:Summary, '##**##')"/>
</xsl:if>
<xsl:if test="contains(ns3:Component/ns3:LoadBearing/ns3:Summary, '##**##')=false()">
<xsl:value-of select="ns3:Component/ns3:LoadBearing/ns3:Summary"/>
</xsl:if>
<xsl:if test="contains(ns3:Component/ns3:LoadBearing/ns3:Summary, '##**##')=true()">
<xsl:value-of select="substring-after(ns3:Component/ns3:LoadBearing/ns3:Summary, '##**##')"/>
</xsl:if>
</b>
</td>
</tr>
<!--</xsl:if >-->
<xsl:if test="ns3:Component/ns3:DrawbarTractor/ns3:Weight!=''">
<tr>
<td>Gross weight:</td>
<td colspan="2">
<xsl:call-template name="parseString">
<xsl:with-param name="list" select="ns3:Component/ns3:DrawbarTractor/ns3:Weight"/>
</xsl:call-template>
<xsl:choose>
<xsl:when test="$UnitType='' or $UnitType=692001">
<xsl:text disable-output-escaping="yes"><![CDATA[ ]]></xsl:text>kg
</xsl:when>
<xsl:otherwise>
<xsl:text disable-output-escaping="yes"><![CDATA[ ]]></xsl:text>kg
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
</xsl:if>
</table>
<br/>
</xsl:for-each>
</xsl:if>
<!--For Non Semi Vehicles Ends here-->
</body>
</html>
</xsl:template>
<!--Changes for RM#4998 start-->
<xsl:template match="text()" name="SplitAlternative">
<xsl:param name="pText" select="."/>
<xsl:param name="pDelim" select="' OR'"/>
<xsl:param name="pCounter" select="1"/>
<xsl:if test="string-length($pText) > 0">
<xsl:variable name="vToken" select=
"substring-before(concat($pText,' OR'), ' OR')"/>
<!--<xsl:value-of select="$vToken"/>
<xsl:text disable-output-escaping="yes"><![CDATA[ , ]]></xsl:text>
<xsl:value-of select="$pCounter"/>-->
<xsl:if test="not($pCounter = 1)">
or<xsl:text disable-output-escaping="yes"><![CDATA[ ]]></xsl:text>
</xsl:if>
<xsl:if test="$UnitType='' or $UnitType=692001">
<xsl:variable name="varKM" select="round(number($vToken) div number(1000))"/>
<xsl:value-of select="$varKM"/> <xsl:text disable-output-escaping="yes"><![CDATA[ ]]></xsl:text>km
</xsl:if>
<xsl:if test="$UnitType=692002">
<xsl:variable name="varMiles" select="round(number($vToken) div number(1760))"/>
<xsl:value-of select="$varMiles"/><xsl:text disable-output-escaping="yes"><![CDATA[ ]]></xsl:text>miles
</xsl:if>
<xsl:call-template name="SplitAlternative">
<xsl:with-param name="pText" select=
"substring-after($pText,'OR')"/>
<xsl:with-param name="pCounter"
select="$pCounter + 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
請爲每個輸入XML文檔顯示一個完整的(和最小的)XSLT樣式表,並清楚地顯示輸出應該是什麼。謝謝。更多幫助:http://stackoverflow.com/help/mcve。 –
XSLT非常大,輸出對此沒有任何影響,我只想要一個IF條件的動態順序。讓我知道是否需要更多的澄清。非常感謝。 –
我_already_讓你知道需要更多的說明。問題在於你的XSLT樣式表非常大。將其分解並在一個非常小的樣式表中隔離您的問題並將其發佈到此處。 –