2016-03-30 25 views
1

對我有這樣的bookmap:的xsl:如果要看一個子節點

<?xml version="1.0" encoding="utf-8"?> 
<bookmap> 
<part> 
    <chapter/> 
    <chapter/> 
    <chapter/> 
</part> 
<part/> 
<part/> 
<part/> 
<part/> 
<appendix/> 
</bookmap> 

我想裏面放上模板,XSL:如果這取決於元素是否part/chapterpart命令。

I.e.我有這些模板processTopicTitle裏面,DITA-OT分發的一部分:

<xsl:if test="bookmap/part/chapter"> 
    <fo:external-graphic src="thisischapter.png" /> 
</xsl:if> 

<xsl:if test="bookmap/part"> 
    <fo:external-graphic src="thisispart.png" /> 
</xsl:if> 

這是行不通的。

的想法是有,只有在部分/章節,另一個上只有部分的那些顯示出來的圖形。

+0

這可能是「不工作」作爲您的背景下將需要的文件節點測試返回true。這可能會有助於看到更多的XSLT給出更全面的答案,特別是模板語句所在的語句。您是否也可以編輯您的問題以顯示您的預期輸出?謝謝。 –

+0

下面是我想要放置diamond.png的部分:(http://josecotes.com/tmp/sample1.txt) 我試圖在每個主題的標題之前放置該圖形,但僅限於只包含*部分內的主題。 * *章內*將不會添加該圖形。 –

回答

0

我做了這樣的工作:

<xsl:template name="insertDiamond"> 
    <xsl:variable name="topicref" select="key('map-id', ancestor-or-self::*[contains(@class,' topic/topic ')][1]/@id)"/> 
    <xsl:choose> 
     <xsl:when test="$topicref//ancestor-or-self::*[contains(@class, ' bookmap/part ')][not(child::*[contains(@class, ' bookmap/chapter ')])]"> 
      <!--Put actions here for parts without any chapters as childs--> 
     </xsl:when> 
     <xsl:otherwise> 
      <!--Put actions here for the rest.--> 
     </xsl:otherwise> 
    </xsl:choose> 
</xsl:template> 
2

你需要做的是這樣的:

<xsl:choose> 
    <!-- parts --> 
    <xsl:when test="$map//*[contains(@class, ' bookmap/part ')]"> 
     <xsl:call-template name="getVariable"> 
      <xsl:with-param name="id" select="'First Cover Image Path'"/> 
     </xsl:call-template> 
    </xsl:when> 
    <!-- chapters --> 
    <xsl:when test="$map//*[contains(@class, ' bookmap/chapter ')]"> 
     <xsl:call-template name="getVariable"> 
      <xsl:with-param name="id" select="'Second Cover Image Path'"/> 
     </xsl:call-template> 
    </xsl:when> 
    <!-- parts without chapters --> 
    <xsl:when test="$map//*[contains(@class, ' bookmap/part ')][not(child::*[contains(@class, ' bookmap/chapter ')])"> 
     <xsl:call-template name="getVariable"> 
      <xsl:with-param name="id" select="'Third Cover Image Path'"/> 
     </xsl:call-template> 
    </xsl:when> 
</xsl:choose> 

你應該在配置文件中定義的圖像~/cfg/common/vars/en.xml

你應該閱讀:

更新

要放置你的形象,你應該使用placeImage模板:

<xsl:apply-templates mode="placeImage" select="."> 
    <xsl:with-param name="imageAlign" select="@align"/> 
    <xsl:with-param name="href" 
        select=" 
        if (@scope = 'external' or opentopic-func:isAbsolute(@href)) then 
         @href 
        else 
         concat($input.dir.url, @href)"/> 
    <xsl:with-param name="height" select="@height"/> 
    <xsl:with-param name="width" select="@width"/> 
</xsl:apply-templates> 

這有利於使用dita-generator生成一個插件,設置自定義封面圖片,然後比較你代碼與生成的插件的代碼。

+0

非常感謝。不幸的是,它沒有按預期工作。這是http://josecotes.com/tmp/sample1.txt部分的鏈接。 現在我添加了這些,但仍然不工作: '     ' –

+0

我添加了一個示例如何使用placeImage模板。你能解釋一下什麼是行不通的嗎? –

+0

我在上面的第一段代碼中進一步測試了這個代碼,所有代碼都返回true。觸發''列表中的第一個''。我刪除了那個,然後第二個是真的,依此類推。 –

相關問題