La función XSLT 2.0 no se ejecuta

Tengo esta plantilla:

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

The regex-group function does what it is supposed to do. However, the generate-id() does not. XMLSPY Debugger stumbles: "error in XPATH 2.0 expression (not a node item)." What do I do wrong? (btw: generate-id(.) does the same)

preguntado el 28 de mayo de 14 a las 13:05

1 Respuestas

Dentro de analyze-string the current context item (.) Es un cadena (the current matching or non-matching substring), not a node, so you can't pass it to 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:

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

(or indeed just cache the ID itself <xsl:variable name="theId" select="generate-id()" />)

contestado el 28 de mayo de 14 a las 13:05

Then every <item> will get the same id, I'm afraid... So I'll be better off with "concat('fontId', position())" - Erik

@Erik indeed, position() dentro analyze-string gives you the position in the "list of matching and non-matching substrings" so in this case it would give you fontId2, fontId4, etc - Ian Roberts

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.