2015-02-09 60 views
0

這是一個類似於Style inline text along with nested tags with XSLT的問題,但我無法評論以獲得解釋,因此我將在此處詳細說明我的具體情況。我基本上有以下結構的XML文檔:我使用XSLT輸出XHTML從我的XML文件使用XSLT設計嵌入式XML標記的樣式

<book> 
    <chapter> 
     <para>This is some text about <place>New York</place></para> 
    </chapter> 
</book> 

,我希望能夠把span標籤什麼的內容周圍的地點標籤中上面的例子。目的是讓我可以用CSS來設計這些段落的文字。下面我上面提到的例子中,我添加了這個:

<xsl:template match="book/chapter/para/place"> 
    <span class="place"> 
     <xsl:apply-templates/> 
    </span> 
</xsl:template> 

當我加載在瀏覽器的XML文檔,我得到的錯誤:「錯誤加載樣式表:解析XSLT樣式表失敗」 (在添加此部分之前,樣式表正確加載)

我假設我對如何使用xsl:apply-templates缺乏一些基本的瞭解。如果有人能指出我的想法,我將不勝感激。

謝謝!

+1

「*我添加了這個:*」 你添加到了什麼?請告訴我們您的整個樣式表,以便我們可以重現問題。 - P.S.瀏覽器的錯誤信息是否指向發生錯誤的行/列? – 2015-02-09 01:01:40

回答

0

比賽:

<xsl:template match="book/chapter/para/"> 

模板適用於所有兒童place,而不是place本身。

使用selectapply-templates代替:

<xsl:template match="/"> 
    <xsl:apply-templates select="book/chapter/para/place"/> 
</xsl:template> 

In the absence of a select attribute, the xsl:apply-templates instruction processes all of the children of the current node, including text nodes.

A select attribute can be used to process nodes selected by an expression instead of processing all children. The value of the select attribute is an expression. The expression must evaluate to a node-set.

參考