Skip to content
This repository has been archived by the owner on Dec 30, 2018. It is now read-only.

Commit

Permalink
changeset: 65:c15372868b58
Browse files Browse the repository at this point in the history
user:        michaelbrauer
date:        Fri Feb 11 10:47:42 2011 +0100
Get old state from document rather than as paramter

git-svn-id: https://svn.apache.org/repos/asf/incubator/odf/trunk@1167901 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
devin committed Aug 26, 2011
1 parent 2e9065c commit e642956
Showing 1 changed file with 51 additions and 7 deletions.
58 changes: 51 additions & 7 deletions xslt-runner/sample_xslt/update-toc-rel-paths.xsl
Expand Up @@ -28,7 +28,7 @@
version="1.0">
<xsl:output method="xml" indent="no"/>

<xsl:param name="state-old" select="'(none)'"/>
<!-- <xsl:param name="state-old" select="'(none)'"/>-->
<xsl:param name="state-new" select="'(none)'"/>

<xsl:variable name="toc-prefix" select="'toc-'"/>
Expand All @@ -38,26 +38,70 @@
<!-- ************************ -->
<!-- ** toc anchors (toc-) ** -->
<!-- ************************ -->
<xsl:template match="text:section[starts-with(@text:name,$toc-prefix)]//text:a[starts-with(@xlink:href,'../')]">
<xsl:variable name="new-href">
<xsl:call-template name="remove-rel-path">
<xsl:with-param name="path" select="@xlink:href"/>
<xsl:template match="text:section[starts-with(@text:name,$toc-prefix)]">
<xsl:variable name="part" select="concat('-',substring(@text:name,string-length($toc-prefix)+1))"/>
<xsl:variable name="state-old">
<xsl:call-template name="get-state">
<xsl:with-param name="path" select="substring-before(.//text:a[starts-with(@xlink:href,'../')][1]/@xlink:href,$part)"/>
</xsl:call-template>
</xsl:variable>
<xsl:message>Old state for <xsl:value-of select="$part"/> is <xsl:value-of select="$state-old"/>.</xsl:message>
<xsl:copy>
<xsl:apply-templates select="@*|node()" mode="in-toc">
<xsl:with-param name="state-old" select="$state-old"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>

<xsl:template name="get-state">
<xsl:param name="path"/>
<xsl:choose>
<xsl:when test="contains($path,'-')">
<xsl:call-template name="get-state">
<xsl:with-param name="path" select="substring-after($path,'-')"/>
</xsl:call-template>
</xsl:variable>
<xsl:message>href: <xsl:value-of select="@xlink:href"/> = <xsl:value-of select="$new-href"/></xsl:message>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('-',$path)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="text:a[starts-with(@xlink:href,'../')]" mode="in-toc">
<xsl:param name="state-old"/>
<xsl:variable name="new-href">
<xsl:call-template name="remove-rel-path">
<xsl:with-param name="path" select="@xlink:href"/>
<xsl:with-param name="state-old" select="$state-old"/>
</xsl:call-template>
</xsl:variable>
<xsl:message>href: <xsl:value-of select="@xlink:href"/> = <xsl:value-of select="$new-href"/></xsl:message>
<text:a>
<xsl:attribute name="xlink:href"><xsl:value-of select="$new-href"/></xsl:attribute>
<xsl:apply-templates select="@*[not(name(.)='xlink:href')]"/>
<xsl:apply-templates select="node()"/>
</text:a>
</xsl:template>

<!-- default: copy everything. -->
<xsl:template match="@*|node()" mode="in-toc">
<xsl:param name="state-old"/>
<xsl:copy>
<xsl:apply-templates select="@*|node()" mode="in-toc">
<xsl:with-param name="state-old" select="$state-old"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>


<xsl:template name="remove-rel-path">
<xsl:param name="path"/>
<xsl:param name="state-old"/>
<xsl:choose>
<xsl:when test="contains($path,'/')">
<xsl:call-template name="remove-rel-path">
<xsl:with-param name="path" select="substring-after($path,'/')"/>
<xsl:with-param name="state-old" select="$state-old"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
Expand Down

0 comments on commit e642956

Please sign in to comment.