Changeset 4439
- Timestamp:
- 02/05/14 10:18:37 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cats/shared/urn.org.isocat.sloot/trunk/tools/xquery.dpml
r4375 r4439 23 23 <literal type="xml"> 24 24 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> 25 <xsl:import href="active:sloot.xquery-wrapers.escape"/> 25 26 <xsl:output method="text"/> 26 27 <xsl:param name="vararg"/> 27 28 <xsl:param name="debug"/> 28 29 <xsl:variable name="NL" select="system-property('line.separator')"/> 29 <xsl:template match=" /">30 <xsl:variable name=" root" select="*"/>30 <xsl:template match="query"> 31 <xsl:variable name="current-node" select="."/> 31 32 <xsl:variable name="query"> 32 33 <!-- turn the namespaces in scope of the root element into 'declare namespace' statements --> 33 34 <xsl:for-each 34 select="in-scope-prefixes($ root)[not(.=('xml','xs','xsi','fn','local'))]">35 select="in-scope-prefixes($current-node)[not(.=('xml','xs','xsi','fn','local'))]"> 35 36 <xsl:variable name="prefix" select="current()"/> 36 37 <xsl:choose> … … 38 39 <xsl:text>declare default namespace "</xsl:text> 39 40 <xsl:value-of 40 select="namespace-uri-for-prefix($prefix,$ root)"/>41 select="namespace-uri-for-prefix($prefix,$current-node)"/> 41 42 <xsl:text>";</xsl:text> 42 43 <xsl:value-of select="$NL"/> … … 47 48 <xsl:text> = "</xsl:text> 48 49 <xsl:value-of 49 select="namespace-uri-for-prefix($prefix,$ root)"/>50 select="namespace-uri-for-prefix($prefix,$current-node)"/> 50 51 <xsl:text>";</xsl:text> 51 52 <xsl:value-of select="$NL"/> … … 61 62 />]</xsl:message> 62 63 </xsl:if> 63 64 64 <xsl:text>declare variable $</xsl:text> 65 65 <xsl:value-of select="$var"/> … … 67 67 <xsl:value-of select="$NL"/> 68 68 </xsl:for-each> 69 <xsl:apply-templates/> 69 <xsl:for-each select="./node()"> 70 <xsl:choose> 71 <xsl:when test="self::text()"> 72 <xsl:apply-templates select="."/> 73 </xsl:when> 74 <xsl:otherwise> 75 <xsl:apply-templates select="." mode="escape"/> 76 </xsl:otherwise> 77 </xsl:choose> 78 </xsl:for-each> 70 79 </xsl:variable> 71 80 <xsl:if test="$debug"> … … 73 82 </xsl:if> 74 83 <xsl:value-of select="$query"/> 75 </xsl:template>76 <!-- turn an element node into an escaped XML string -->77 <xsl:template match="*">78 <xsl:text><</xsl:text>79 <xsl:value-of select="name()"/>80 <xsl:apply-templates select="@*"/>81 <xsl:text>></xsl:text>82 <xsl:apply-templates/>83 <xsl:text></</xsl:text>84 <xsl:value-of select="name()"/>85 <xsl:text>></xsl:text>86 </xsl:template>87 <!-- turn an attribute node into an escaped XML string -->88 <xsl:template match="@*">89 <xsl:text> </xsl:text>90 <xsl:value-of select="name()"/>91 <xsl:text>="</xsl:text>92 <xsl:value-of93 select="replace(replace(replace(replace(replace(.,'&','&amp;'),'''','&apos;'),'<','&lt;'),'>','&gt;'),'"','&quot;')"/>94 <xsl:text>"</xsl:text>95 </xsl:template>96 <!-- turn a text node into an escaped XML string -->97 <xsl:template match="text()">98 <xsl:value-of select="normalize-space(.)"/>99 84 </xsl:template> 100 85 </xsl:stylesheet>
Note: See TracChangeset
for help on using the changeset viewer.