Skip to content

Instantly share code, notes, and snippets.

@veged
Created March 17, 2009 07:21
Show Gist options
  • Save veged/80385 to your computer and use it in GitHub Desktop.
Save veged/80385 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="index.xsl"?>
<page xmlns:xi="http://www.w3.org/2001/XInclude"/>
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/page">
<result>
<xsl:for-each select="namespace::*">
<!-- только вызов шаблона -->
<xsl:apply-templates select="/" mode="namespace">
<xsl:with-param name="namespace" select="."/>
</xsl:apply-templates>
</xsl:for-each>
<xsl:text> == </xsl:text>
<xsl:apply-templates select="namespace::*" mode="only-namespaces"/>
</result>
</xsl:template>
<!-- шаблон, который можно переопределить с предикатом -->
<xsl:template match="/" mode="namespace">
<xsl:param name="namespace"/>
<xmlns>
<xsl:value-of select="name($namespace)"/>
</xmlns>
</xsl:template>
<!-- этот шаблон не сматчится после <xsl:apply-templates select="namespace::*" mode="only-namespaces"/> -->
<!-- это противоречит спецификации - http://www.w3.org/TR/1999/REC-xslt-19991116#patterns -->
<!-- ходят СЛУХИ (http://www.biglist.com/lists/xsl-list/archives/200303/msg00092.html) что это исправили в спецификации -->
<xsl:template match="node()" mode="only-namespaces">
<xsl:apply-templates select="/" mode="namespace">
<xsl:with-param name="namespace" select="."/>
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment