2011-01-25 60 views
1

我正在處理一些包含和/或標記的xml文件。我想將它們轉換爲 html。在我的XSL我使用兩個模板如何在XPath中使用Jre default處理器獲取元素<and>和<or>處理器(JAXPSAXProcessor)

<xsl:template match="and"> 
    (
    <xsl:apply-templates select="./*[1]" /> 
    <xsl:text> </xsl:text> 
    <xsl:value-of select="name(.)" /> 
    <xsl:text> </xsl:text> 
    <xsl:apply-templates select="./*[2]" /> 
    ) 
</xsl:template> 
<xsl:template match="or"> 
    (
    <xsl:apply-templates select="./*[1]" /> 
    <xsl:text> </xsl:text> 
    <xsl:value-of select="name(.)" /> 
    <xsl:text> </xsl:text> 
    <xsl:apply-templates select="./*[2]" /> 
    ) 
</xsl:template> 

當我使用的Xalan作爲處理器它工作的,但是當我使用JAXPSAXProcessor我得到錯誤: 錯誤[主] JAXPSAXProcessorInvoker - 語法錯誤「或」。 錯誤[main] JAXPSAXProcessorInvoker - '和'中的語法錯誤。

我想JaxPSaxProcessor轉換和/或運算符在Xpath中。 here you can see the list of operators 我無法更改jaxb處理器,因爲它已在許多地方使用。有沒有其他的解決辦法可以解決這個問題?

+0

好問題,+1。看到我的答案,你可以嘗試一些技巧。 – 2011-01-25 14:12:23

回答

1

如果XSLT處理器越野車,您可以嘗試使用一些技術,如欺騙它:

<xsl:template match="*[name()=concat('a', 'nd')"> 

<xsl:template match="*[name()=substring('land',2)"> 

好運。

+0

+1好答案。我認爲即使`* [name()='和']`應該避免在錯誤的XPath解析器中發生衝突。 – 2011-01-25 15:12:54