我已经成功地找到并用 XSL 替换了一个 XML 标记,但是发现我的 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 baby-recipe”的任何行包装。到目前为止,他们的 uid 都是“877”,并且使用 run[@p='877'] 已经奏效。但是,可能存在 uid 不是“877”的情况。因此,需要我的“匹配”语句来查找其中 p 等于名称为“Head baby-recipe”的 parastyle 的 uid。这有点复杂,我还没有想出为此工作的 XSL。
任何帮助表示赞赏!