xsl-list
[Top] [All Lists]

Re: [xsl] Extracting a fragment between milestones from a complex structure.

2011-03-03 14:06:33

Thanks David, that does the trick. Since their is no guaranty that the
@n attributes are in order, I've adjusted the solution a little to look
up the next pb element; but it would be even nicer if that too could be
avoided, also using explicit priorities to avoid excessive warnings.
Works both with XSLT 1.0 and 2.0, which makes it easier to deploy on my
site.

Jeroen.

<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
    version="2.0">

    <xsl:output
        method="xml"
        indent="yes"
        encoding="UTF-8"/>

    <xsl:param name="n" select="12"/>

    <xsl:variable name="m">
        <xsl:value-of select="//pb[@n=$n]/following::pb[1]/@n"/>
    </xsl:variable>

    <xsl:template match="node()" priority="1"/>

    <xsl:template match="*[descendant-or-self::pb/@n=$n] |
node()[preceding::pb/@n=$n]" priority="2">
         <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="node()[preceding::pb/@n=$m or self::pb/@n=$m]"
priority="3"/>

</xsl:stylesheet>


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>