0

我有一个如下的 XML 文件:

<NOP>A focus on individual exhibitors is essential, though, in order to 
  understand how these figures influenced American (and global) culture and 
  how audiences were attracted to movies and movie theaters. Charles Musser 
  writes in his examination of Lyman Howe’s career that “a focus on 
  exhibition lends itself to industrial history precisely because it must 
  address the economic basis of the motion picture industry—the showman’s 
  ability to bring patrons through the front door.â€&lt;ENREF>1</ENREF> In order 
  to understand the artistic and managerial influences of showmen like Samuel 
  Lionel Rothafel (“Roxyâ€) and Sidney Patrick Grauman, one must analyze 
  their construction of stardom, their ethnic heritage and cultural background, 
  their facility with music, theater, film, and other performing arts, and the 
  ways in which they motivated patrons to enter their “front door.â€
</NOP>

我将以下 XSLT 与 XML 间谍一起使用,但它不适用于“ENREF”。任何帮助

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
  <xsl:template match="NOP">
  <div class="no-indent"><span><xsl:value-of select="."/></span></div>
  </xsl:template>
  <xsl:template match="ENREF">
    <small>
    <sup>
     <xsl:element name="a">
      <xsl:attribute name="id">enref-<xsl:value-of select="."/></xsl:attribute>
      <xsl:attribute name="href">#fn<xsl:value-of select="."/></xsl:attribute>
      <xsl:value-of select="."/>
     </xsl:element>
    </sup>
    </small>
 </xsl:template>
</xsl:stylesheet>
4

1 回答 1

1

编写一个匹配某个元素的模板是不够的,您还需要确保该元素被处理。您没有向我们展示您想要的结果,所以我必须猜测您想要实现的目标,但首先尝试改变

  <xsl:template match="NOP">
  <div class="no-indent"><span><xsl:value-of select="."/></span></div>
  </xsl:template>

  <xsl:template match="NOP">
  <div class="no-indent"><span><xsl:apply-templates/></span></div>
  </xsl:template>

这样,NOP元素的子节点可以通过内置模板(确保<xsl:apply-templates/>为孙子和后代保持处理)或您的模板(如ENREF元素的模板)进行处理。

于 2012-12-14T10:19:47.393 回答