我在XSLT中尝试了一个代码,它只在输出中正确显示。但两次来,
XML输入文件是:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic
PUBLIC "urn:pubid:com.saffron.doctypes:doctypes:dita:topic" "topic.dtd">
<topic>
<title class="- topic/title " outputclass="MLU">Non-Insulin Injections: Up Close and
Personal</title>
<body>
<p class="- topic/p " outputclass="MLU_Code">W3333</p>
<p class="- topic/p " outputclass="MLU_Condition">Injections</p>
<p class="- topic/p " outputclass="MLU_Type">Select & Reflect</p>
</body>
</topic>
我使用的XSL:
<xsl:template match="title[@outputclass='MLU'] | p[@outputclass='MLU_Code']">
<trackingSettings>
<urlcode>
<xsl:value-of select="//p[@outputclass='MLU_Code']"/>
</urlcode>
<apiurl>http://mlucenter.com/like/api</apiurl>
</trackingSettings>
<page></page>
<xsl:apply-templates select="p[@outputclass='MLU_Code']"/>
<banner>
<enabled>true</enabled>
<text>
<xsl:value-of select="//title[@outputclass='MLU']"/>
</text></banner>
<xsl:apply-templates select="title[@outputclass='MLU']"/>
</xsl:template>
获取输出是:
<trackingSettings><urlcode>W3333</urlcode><apiurl>http://mlucenter.com/like/api</apiurl></trackingSettings>
<page/>
<banner><enabled>true</enabled>
<text>Non-Insulin Injections: Up Close and Personal</text></banner>
<trackingSettings><urlcode>W3333</urlcode><apiurl>http://mlucenter.com/like/api</apiurl></trackingSettings>
<page/>
<banner><enabled>true</enabled>
<text>Non-Insulin Injections: Up Close and Personal</text></banner
>
我需要输出元素立刻出现。请指导该XSLT代码。感谢
答案 0 :(得分:0)
你的OR'|'条件强制运行两次。
xsl:template match =“title [@ outputclass ='MLU'] | P [@ OutputClass类= 'MLU_Code']“&GT;
总是更好,并建议将问题分开。
您需要首先按/ topic(root)匹配才能开始,然后调用单独的模板。
<xsl:template match="/topic">
<!-- invoke your separate templates-->
</xsl:template>