2017-05-01 43 views
0

我有其中過濾所需要的「對位」元素如何在xml中過濾段落?

<multitest.document version="1" publication.number="356456" 
    filterusing="a"> 
    <life quotes> 
    <para.set> 
     <para change.bar="no" language="en_ww" filter="a">Your work is going 
     to fill a large part of your life, and the only way to be truly 
     satisfied is to do what you believe is great work. 
     </para> 
    </para.set> 
    <para.set> 
     <para change.bar="no" language="en_ww" filter="b">Your work is going 
     to fill a large part of your life, and the only way to be truly 
     satisfied is to do what you believe is great work. 
     </para> 
     </para.set> 
     <para.set> 
     <para change.bar="no" language="en_ww" filter="c">Your work is going 
     to fill a large part of your life, and the only way to be truly 
     satisfied is to do what you believe is great work. 
     </para> 
     </para.set> 
     </life.quotes> 

    <general quotes> 
    <para.set> 
    <para> 
    Where there is a will there is a way and never give up in life 
    </para> 
    </para.set> 
    </general quotes> 

上被施加在這個例子中的XML文檔,作者設置「filterusing」屬性設置爲「是」,所以在這樣的塊當檢查具有filter屬性的段落的規則(para/[@ filter])時,它將該值與過濾器使用值匹配並處理第一段。其他人被忽略,因爲他們不匹配filterusing變量。

如果filterusing,濾除已設置爲「是」,那麼對只應該得到處理和其他段應被忽略,並且沒有過濾器的那些通常應像一般報價

處理

如果未應用過濾器,則應該按原樣顯示該段。

<xsl:param name="filter"></xsl:param> 
<xsl:template match="//para[@filter]"> 
    <xsl:choose> 
    <xsl:when test="[email protected]"> 
    <fo:block xsl:use-attribute-sets="filtering_1_atts"> 
    <xsl:value-of select="para[@language=$active_language]"/> 
    </fo:block> 
</xsl:when> 
    <xsl:when test="@filterusing!='$filter'"> 
    <fo:block xsl:use-attribute-sets="filtering_1_atts"> 
    <xsl:value-of select="."></xsl:value-of> 
    </fo:block> 
    </xsl:when> 
    <xsl:otherwise> 
    <fo:block xsl:use-attribute-sets="filtering_1_atts"> 
     <xsl:value-of select="para[@language=$active_language]"/> 
     </fo:block> 
    </xsl:otherwise> 
</xsl:choose> 
</xsl:template> 

即使過濾器使用和過濾器都設置爲「a」,該段仍未顯示。

我對這項技術很陌生,所以請幫助我。

回答

2

此聲明<xsl:template match="//para[@filter]">將當前節點設置爲<para>

因此,<xsl:when test="[email protected]">$filter@filterusing的屬性<para>相比較。

您需要解決包含@filterusing屬性節點:問題的<xsl:when test="$filter=ancestor::multitest.document/@filterusing">

第二個版本:你已經改變了模板匹配<xsl:template match="//para/@filter">。這會嘗試僅匹配para節點的過濾器屬性,因此不起作用。

+0

lakshmi

+0

它沒有工作 – lakshmi

+1

你已經改變了e模板匹配語句,並在那裏引入錯誤。 – Hobbes

0
<xsl:variable name="filterVariable" 
    select="multitest.document/@filterusing"></xsl:variable> 
    <xsl:template match="para[@filter]"> 
    <xsl:choose> 
    <xsl:when test="[email protected]"> 
     <xsl:value-of select="para[@language=$active_language]"/> 
     <xsl:apply-templates/> 
     </xsl:when> 
     <xsl:when test="not([email protected])"> 
     </xsl:when> 
    <xsl:otherwise> 
     <xsl:value-of select="para[[email protected]]"/> 
      <xsl:apply-templates/> 
    </xsl:otherwise> 
    </xsl:choose> 

以上是溶液ñ它工作正常