我仍然收到以下错误
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> </xsl:text>
</xsl:template>
</xsl:stylesheet>
请不要回复,引号会将'tagName'作为字符串并删除这些引号。这个值实际上将从java作为字符串传递,tats y用于测试目的我将此xpath作为字符串传递。
答案 0 :(得分:0)
根据在线文档http://www.saxonica.com/documentation9.1/extensions/functions.html,Saxon 9.1支持an evaluate
function in the Saxon namespace 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]"/>
就足够了。