代码之家  ›  专栏  ›  技术社区  ›  Tchob

文档功能为空

  •  0
  • Tchob  · 技术社区  · 9 年前

    我有一个这样的变量:

    <xsl:variable name="link_Description">
    <xsl:choose>
      <xsl:when test="/map/topicref/@navtitle = 'Description'">
        <xsl:value-of select="/map/topicref[@navtitle='Description']/@href"/>
      </xsl:when>
      <xsl:when test="/map/topicref/@navtitle = '产品描述'">
        <xsl:value-of select="/map/topicref[@navtitle='产品描述']/@href"/>
      </xsl:when>
      <xsl:when test="/map/topicref/@navtitle = '説明'">
        <xsl:value-of select="/map/topicref[@navtitle='説明']/@href"/>
      </xsl:when>
    </xsl:choose>
    </xsl:variable>
    

    此变量返回文档的文件名:TAMS030141848SMD_zh-cn.dita

    问题是当我应用一个document()函数时: document($link_Description) 没有回报。

    在我检查中文和日文之前,我使用了这个变量:

    <xsl:variable name="link_Description" select="/map/topicref[@navtitle='Description']/@href"/>
    

    使用这个变量,document()函数 文档($link_Description) 返回了好结果

    DITA XML代码输入:

     <map id="DocID026018" rev="2" title="STHV800" class="- map/map " xml:lang="zh-cn">
       <topicref navtitle="Features" class="- map/topicref " href="TAMS0303141517SMD_zh-cn.dita"/>
       <topicref navtitle="Description" class="- map/topicref " href="TAMS0303141848SMD_zh-cn.dita" />
       <topicref navtitle="sdfsdf" class="- map/topicref " href="TAMS0303141932SMD_zh-cn.dita"/>
    </map>
    
    1 回复  |  直到 9 年前
        1
  •  1
  •   Michael Kay    9 年前

    我认为问题可能是当你使用

    <xsl:variable name="v" select="/a/b/c"/>
    

    变量的值是源文档中的一个节点,具有源文档的基URI,但当您这样做时

    <xsl:variable name="w">
      <xsl:value-of select="/a/b/c"/>
    </xsl:variable>
    

    那么变量的值是一个新构造的节点,其基URI是样式表的基URI。如果源文档包含与源文档相关的相对URI,则需要使用document()的第二个参数将基URI设置为源文档URI:

    document($w, /)
    

    或者,使变量不那么冗长:

    <xsl:variable name="link_Description" 
    select="/map/topicref[@navtitle = ('Description', '产品描述', '説明')][1]/@href"/>