Search code examples
xmlxsltfilenamesxslt-2.0dita

Document function empty


I have a variable like this :

<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>

This variable return the filename of my document : TAMS0303141848SMD_zh-cn.dita

The probleme is when I apply a document() fonction like this : document($link_Description) nothing is return.

Before I checked the Chinese and the Japanese, I used this variable :

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

And with this varible the document() function document($link_Description) returned the good result

DITA XML code input :

 <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>

Solution

  • I think the problem is probably that when you use

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

    the value of the variable is a node in your source document, with the base URI of the source document, but when you do

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

    then the value of the variable is a newly constructed node, whose base URI is that of the stylesheet. If your source document contains relative URIs that are relative to the source document, you will need to use the second argument of document() to set the base URI to the source document URI:

    document($w, /)
    

    Alternatively, make the variable less verbose:

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