我几乎是第一次使用 xslt 和 xpath,所以请多多包涵。我有以下xml(这只是其中的一小部分):
<scriptflow description="" entrynodeid="301033924" leftbranch="809" name="Annual Charge and Banding v1.0" quickcode="" rightbranch="810" scriptflowid="301001711" status="1" templateid="-1">
- <scriptnode eventid="-1" name="Annual Charge" nodeid="301033924" templateid="1" templatename="action" text="[bookmark=action]Use Information on right hand screen to advise the customer of their annual charge" url="" xpos="100" ypos="130">
<scriptnodeexit exitid="0" exitname="Info Provided" />
<scriptnodeexit exitid="1" exitname="Does NOT Know Property Band" />
<scriptnodeexit exitid="2" exitname="Customer Referred To Valuation Office" />
<scriptnodeexit exitid="3" exitname="Transfer To Council Tax/Offer DDI" />
</scriptnode>
<subprocessnode nodeid="301033925" scriptflowid="101000700" scriptflowname="Anything Else v1.0" xpos="530" ypos="10" />
<subprocessnode nodeid="301033926" scriptflowid="101000733" scriptflowname="Revenue Services - Enquiry Transfer v1.0" xpos="300" ypos="360" />
<eventnode eventid="1474" name="Banding Charge" nodeid="301033927" xpos="346" ypos="50" />
- <scriptnode eventid="-1" name="Search for Banding" nodeid="301033928" templateid="1" templatename="action" text="[bookmark=action]Enter postcode and click on go <BR> <BR> Then enter house name/number and click on go [/bookmark]" url="" xpos="420" ypos="84">
<scriptaction command="http://www.bracknell-forest.gov.uk/counciltaxbandreductions" componentid="10" type="0" />
<scriptnodeexit exitid="0" exitname="Found Banding" />
<scriptnodeexit exitid="1" exitname="Property In Another Borough" />
<scriptnodeexit exitid="2" exitname="Banding NOT Found - Transfer To Revenue Services" />
</scriptnode>
- <scriptnode eventid="-1" name="Details" nodeid="301033929" templateid="1" templatename="action" text="[bookmark=action]If customer is not happy with the information given, please refer them to valuation office [/bookmark]" url="" xpos="760" ypos="287">
<scriptaction command="http://www.bracknell-forest.gov.uk/your-council/yc-council-tax/yc-amount-payable.htm" componentid="10" type="0" />
<scriptnodeexit exitid="0" exitname="Customer Happy With Information" />
<scriptnodeexit exitid="1" exitname="Customer Not Happy Offer Valuation Office Details" />
</scriptnode>
<eventnode eventid="1474" name="Banding Charge" nodeid="301033930" xpos="1016" ypos="20" />
<subprocessnode nodeid="301033931" scriptflowid="101000700" scriptflowname="Anything Else v1.0" xpos="1120" ypos="20" />
- <scriptnode eventid="-1" name="Valuation" nodeid="301033932" templateid="1" templatename="action" text="[bookmark=action] If their propery banding is showing another authority, give them their details by click on authority name on right hand screen [/bookmark]" url="" xpos="810" ypos="190">
<scriptnodeexit exitid="0" exitname="Continue" />
</scriptnode>
- <scriptnode eventid="-1" name="Valuation Details" nodeid="301033933" templateid="1" templatename="action" text="[bookmark=action]Give customer details of the valuation office[/bookmark]" url="" xpos="1080" ypos="270">
<scriptnodeexit exitid="0" exitname="Continue" />
</scriptnode>
- <scriptnode eventid="-1" name="In Another Area" nodeid="301033934" templateid="1" templatename="action" text="[bookmark=action]Click on the authority name to find contact details[/bookmark]" url="" xpos="743" ypos="69">
<scriptnodeexit exitid="0" exitname="Continue" />
</scriptnode>
<subprocessnode nodeid="301033935" scriptflowid="101000733" scriptflowname="Revenue Services - Enquiry Transfer v1.0" xpos="800" ypos="120" />
<nodelink fromnode="301033924" fromnodeexit="0" tonode="301033927" />
<nodelink fromnode="301033924" fromnodeexit="1" tonode="301033928" />
<nodelink fromnode="301033924" fromnodeexit="2" tonode="301033932" />
<nodelink fromnode="301033924" fromnodeexit="3" tonode="301033926" />
<nodelink fromnode="301033927" fromnodeexit="0" tonode="301033925" />
<nodelink fromnode="301033928" fromnodeexit="0" tonode="301033929" />
<nodelink fromnode="301033928" fromnodeexit="1" tonode="301033934" />
<nodelink fromnode="301033928" fromnodeexit="2" tonode="301033935" />
<nodelink fromnode="301033929" fromnodeexit="0" tonode="301033930" />
<nodelink fromnode="301033929" fromnodeexit="1" tonode="301033933" />
<nodelink fromnode="301033930" fromnodeexit="0" tonode="301033931" />
<nodelink fromnode="301033932" fromnodeexit="0" tonode="301033930" />
<nodelink fromnode="301033933" fromnodeexit="0" tonode="301033930" />
<nodelink fromnode="301033934" fromnodeexit="0" tonode="301033930" />
</scriptflow>
我需要从这个 xml 创建一个流程图。将一个节点链接到另一个节点的内容位于此 xml 的末尾:
<nodelink fromnode="301033924" fromnodeexit="0" tonode="301033927" />
....
<nodelink fromnode="301033933" fromnodeexit="0" tonode="301033930" />
<nodelink fromnode="301033934" fromnodeexit="0" tonode="301033930" />
</scriptflow>
我到目前为止的xslt如下:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
<xsl:output method="html" />
<xsl:param name="logo"></xsl:param>
<xsl:param name="folder"></xsl:param>
<xsl:key name="Keytest" match="scriptnode/scriptnodeexit[@exitid]" use="@exitid"/>
<xsl:template match="nodelink">
<xsl:for-each select=".">
<xsl:choose>
<xsl:when test="(preceding-sibling::scriptnode/@nodeid)mod @fromnode=0">
NodeID:<xsl:value-of select="preceding-sibling::scriptnode/@nodeid"/>,
Name:<xsl:value-of select="preceding-sibling::scriptnode/@name"/>,
</xsl:when>
<xsl:otherwise>
<xsl:text>*no nodeID/name match*</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<xsl:choose>
<xsl:when test="(preceding-sibling::scriptnode/scriptnodeexit/@exitid) mod @fromnodeexit=0 and (preceding-sibling::scriptnode/@nodeid) div @fromnode=1 and (preceding-sibling::scriptnode/@nodeid) = @fromnode">
From Node ExitID: <xsl:value-of select="@fromnodeexit"/>
From Node ID: <xsl:value-of select="@fromnode"/>,
ExitID:<xsl:value-of select="preceding-sibling::scriptnode/scriptnodeexit/@exitid"/>,
Exitname:<xsl:value-of select="preceding-sibling::scriptnode/scriptnodeexit/@exitname"/>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="(preceding-sibling::scriptnode/scriptnodeexit/@exitid)mod @fromnodeexit=0">
ExitID:<xsl:value-of select="preceding-sibling::scriptnode/scriptnodeexit/@exitid"/>,
Exitname:<xsl:value-of select="preceding-sibling::scriptnode/scriptnodeexit/@exitname"/>
<img src="{$logo}" />
</xsl:when>
<xsl:otherwise>
<xsl:text>*no editID/exitname match*</xsl:text><img src="{$logo}" />
</xsl:otherwise>
</xsl:choose>
FromNodeExitID:<xsl:apply-templates select="@fromnodeexit"/>,
From Node: <xsl:apply-templates select="@fromnode"/>,
To Node: <xsl:apply-templates select="@tonode"/>
<img src="{$logo}" /><br />
</xsl:template>
</xsl:stylesheet>
我正在尝试创建一个树结构以供以后格式化以使其成为流程图,但我正在努力循环遍历 scriptnode/scptnode 退出属性。我无法上传所需流程图的图像,但我的 xslt 是在正确的轨道上还是完全关闭?