1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| <xsl:template match="url">
<xsl:copy>
<xsl:choose>
<xsl:when test="contains(.,'?')">
<xsl:call-template name="proc_url">
<xsl:with-param name="s" select="normalize-space()" />
<xsl:with-param name="qvar" select="'v'" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="normalize-space()" />
</xsl:otherwise>
</xsl:choose>
</xsl:copy>
</xsl:template>
<xsl:template name="proc_url">
<xsl:param name="s" />
<xsl:param name="qvar" select="'v'" />
<xsl:variable name="lead">
<xsl:call-template name="proc_lead">
<xsl:with-param name="in" select="substring-before($s,'?')" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="trail">
<xsl:call-template name="proc_trail">
<xsl:with-param name="in" select="substring-after($s,'?')" />
<xsl:with-param name="qvar" select="$qvar" />
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test="$trail!=''">
<xsl:value-of select="concat($lead,'/',$trail)" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($lead,'/',$qvar)" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="proc_lead">
<xsl:param name="in" />
<!-- if no '/', it would be empty string if so desired -->
<xsl:value-of select="substring-before($in,'/')" />
<xsl:if test="contains(substring-after($in,'/'),'/')">
<xsl:value-of select="'/'" />
<xsl:call-template name="proc_lead">
<xsl:with-param name="in" select="substring-after($in,'/')" />
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="proc_trail">
<xsl:param name="in" />
<xsl:param name="qvar" />
<xsl:variable name="lead">
<xsl:choose>
<xsl:when test="contains($in,'&')">
<xsl:value-of select="substring-before($in,'&')" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$in" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="trail" select="substring-after($in,'&')" />
<!-- If no '=' it won't be very functional if not incorrect, all would understand to result in empty. -->
<xsl:variable name="qname" select="substring-before($lead,'=')" />
<xsl:variable name="qvalue" select="substring-after($lead,'=')" />
<xsl:if test="$qname=$qvar">
<xsl:value-of select="concat($qvar,'/',$qvalue)" />
</xsl:if>
<xsl:if test="$qname!=$qvar and $trail!=''">
<xsl:call-template name="proc_trail">
<xsl:with-param name="in" select="$trail" />
<xsl:with-param name="qvar" select="$qvar" />
</xsl:call-template>
</xsl:if>
</xsl:template> |
Partager