2013-05-07 55 views
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>&lt;strong&gt;</xsl:text><xsl:value-of select="."/><xsl:text>&lt;/strong&gt;</xsl:text> 
</xsl:template> 

此包裹有期望的标签选择的行。但是,我真正需要的是用任何名称为“Head babies-recipe”的行包装。到目前为止,他们都有一个“877”uid,并使用运行[@ p ='877']已经工作。然而,可能有一个实例是uid不是“877”。因此,需要我的'匹配'语句来寻找一个where p等同于名称为“Head babies-recipe”的parastyle的uid。这有点复杂,我还没有能够为此提供可用的XSL。

任何帮助表示赞赏!

回答

1

它应该是类似的东西(关于 “的署名”):

run[@p=/article/parastyles/parastyle[@name='Byline Name']/@uid] 
+1

谢谢!我的情况的最终XSL是: ' <strong> </strong > CMarcera 2013-05-07 17:40:31