1
我已經成功找到並用XSL替換了一個XML標籤,但發現了一個我的XSL可能無法使用的情況。基於另一個元素的屬性值的XSL模板匹配
源XML:
<article>
<parastyles>
<parastyle name="Headline Bold" uid="876"/>
<parastyle name="Head babies-recipe" uid="877"/>
<parastyle name="Byline Paper" uid="885"/>
<parastyle name="Byline Name" uid="886"/>
<parastyle name="Body Copy" uid="904"/>
</parastyles>
<charstyles>
<charstyle name="[None]" uid="103"/>
</charstyles>
<story name="body">
<runs>
<run p="886" c="103">By AUTHOR NAME
<eol/>
</run>
<run p="885" c="103">Local Writer
<eol/>
</run>
<run p="904" c="103">CITY — Borough Police en
<eol hyphenated="true"/>
countered three men in separate cases
<eol/>
recently who all claimed they had for
<eol hyphenated="true"/>
gotten they were carrying drugs or drug
<eol/>
paraphernalia until an officer started
<eol/>
asking questions.
</run>
<run p="877" c="103">
Forgot joints
<eol/>
</run>
<run p="904" c="103">
In another case, City
<eol/>
Police were called to a home
<eol/>
on LaSalle Street March 30
<eol/>
for a report of a man banging
<eol/>
on the door.
<eol/>
</run>
<run p="877" c="103">
Forgot pipe
<eol/>
</run>
<run p="904" c="103">
In a third case, Ptlm. Raf
<eol hyphenated="true"/>
ferty spotted a young man
<eol/>
running along West Second
<eol/>
Street and ducking into an
<eol/>
area near the Salvation Army
<eol/>
drop-off on March 28 around
<eol/>
1:40 a.m.
<eol/>
</run>
</runs>
</story>
</article>
我的XSL如下:
<xsl:template match="run[@p='877']">
<xsl:text><strong></xsl:text><xsl:value-of select="."/><xsl:text></strong></xsl:text>
</xsl:template>
此包裹有期望的標籤選擇的行。但是,我真正需要的是用任何名稱爲「Head babies-recipe」的行包裝。到目前爲止,他們都有一個「877」uid,並使用運行[@ p ='877']已經工作。然而,可能有一個實例是uid不是「877」。因此,需要我的'匹配'語句來尋找一個where p等同於名稱爲「Head babies-recipe」的parastyle的uid。這有點複雜,我還沒有能夠爲此提供可用的XSL。
任何幫助表示讚賞!
謝謝!我的情況的最終XSL是: ' <strong> </strong > xsl:template> –
CMarcera
2013-05-07 17:40:31