简体   繁体   English

XSLT 2.0函数未执行

[英]XSLT 2.0 function not executing

I have this template: 我有这个模板:

<xsl:template match="opf:manifest">
    <xsl:copy>
    <xsl:analyze-string select="unparsed-text('Styles/fonts.css')" regex='url\(\"(.*[^\"]*)\"\)'>
        <xsl:matching-substring>
            <xsl:element name="opf:item">
                <xsl:attribute name="href" select="regex-group(1)"/> 
                <xsl:attribute name="media-type">application/vnd.ms-opentype
                </xsl:attribute>
                <xsl:attribute name="id" select="generate-id()"/> 
            </xsl:element>
        </xsl:matching-substring>
    </xsl:analyze-string>
    <xsl:apply-templates select="document('index.xml')//opf/(jpeg | scripts)"/>
    <xsl:apply-templates select="document('index.xml')/numberGroup/entry/file"/>
    </xsl:copy>
</xsl:template>

The regex-group function does what it is supposed to do. regex-group函数完成了它应该做的事情。 However, the generate-id() does not. 但是,generate-id()没有。 XMLSPY Debugger stumbles: "error in XPATH 2.0 expression (not a node item)." XMLSPY调试器发现:“ XPATH 2.0表达式中的错误(不是节点项)。” What do I do wrong? 我做错了什么? (btw: generate-id(.) does the same) (顺便说一句:generate-id(。)的作用相同)

Inside analyze-string the current context item ( . ) is a string (the current matching or non-matching substring), not a node, so you can't pass it to generate-id . analyze-string ,当前上下文项( . )是字符串 (当前匹配或不匹配的子字符串),而不是节点,因此您不能将其传递给generate-id If what you want is the generated ID of the node that the current template matched then you need to cache it in a variable outside the analyze-string and then use that variable with generate-id : 如果您想要的是当前模板匹配的节点的生成ID,则需要将其缓存在analyze-string之外的变量中,然后将该变量与generate-id

<xsl:variable name="dot" select="." />
<xsl:analyze-string select="unparsed-text('Styles/fonts.css')" regex='url\(\"(.*[^\"]*)\"\)'>
    <xsl:matching-substring>
        <!-- ... -->
        <xsl:attribute name="id" select="generate-id($dot)"/>

(or indeed just cache the ID itself <xsl:variable name="theId" select="generate-id()" /> ) (或者实际上只是缓存ID本身<xsl:variable name="theId" select="generate-id()" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM