1

我仍然收到以下错误

Error at xsl:param on line 6 of file:/E:/saxon/parastyleText.xsl:
  XPST0003: XPath syntax error at char 0 on line 6 in {...le/@w:val[matches(., c
oncat...}:
    Invalid character '^' in expression
Failed to compile stylesheet. 1 error detected.

修改后的 XSL:

   <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
     xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml">

    <xsl:param name="styleName" select="'articletitle'"/>
    <xsl:param name="tagName" select="'//w:p[w:pPr/w:pStyle/@w:val[matches(., concat('^(',$styleName,')$'),'i')]]'"/>

    <xsl:output method="text"/>

    <xsl:template match="/">
        <xsl:value-of select="saxon:evaluate($tagName)" xmlns:saxon="http://saxon.sf.net/"/><xsl:text>&#10;</xsl:text>
    </xsl:template>

    </xsl:stylesheet>

请不要回复,引号会将“tagName”作为字符串并删除这些引号。该值实际上将作为字符串从 java 传递,出于测试目的,我已将此 xpath 作为字符串传递。

4

1 回答 1

0

根据在线文档http://www.saxonica.com/documentation9.1/extensions/functions.html Saxon 9.1 支持Saxon 命名空间中evaluate函数http://saxon.sf.net/。所以用 Saxon 9.1 试试<xsl:value-of select="saxon:evaluate($tagName)" xmlns:saxon="http://saxon.sf.net/"/>。当然,xsl:stylesheet如果您愿意,您可以将命名空间声明上移到元素上,我只是将它放在xsl:value-of这篇文章中,作为一个简短但完整的代码示例。

另请注意,使用您的变量命名tagName时,您很可能只有一个元素名称,在这种情况下,使用<xsl:value-of select="*[local-name() eq $tagName]"/>.

于 2012-11-01T11:36:25.387 回答