XML Tutorial/XSLT stylesheet/local name

Материал из Web эксперт
Версия от 18:22, 25 мая 2010; (обсуждение)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Functions name, local-name, and namespace-uri() are used to get informations about element and attribute names and namespaces

local-name()- Takes zero or one node-sets as its argument and returns the local part of the element name if it exists; if no argument node-set exists, it returns the local part of the name of the context node.  

File: Data.xml
<?xml version="1.0" encoding="utf-8"?>
<data xmlns:standard="http://www.w3.org/1999/XSL/Transform"
      xmlns:wbex="http://www.wbex.ru">
    <standard:id>standardAAA</standard:id>
    <standard:size>258</standard:size>
    <wbex:id>wbex1258</wbex:id>
</data>
File: Transform.xslt
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
      <TABLE border="1">
        <TR>
          <td>name</TH>
          <td>local</TH>
          <td>URI</TH>
        </TR>
        <xsl:apply-templates select="//*"/>
      </TABLE>
    </xsl:template>
    <xsl:template match="*">
      <TR>
        <TD>
          <xsl:value-of select="name()"/>
        </TD>
        <TD>
          <xsl:value-of select="local-name()"/>
        </TD>
        <TD>
          <xsl:value-of select="namespace-uri()"/>
        </TD>
      </TR>
    </xsl:template>
</xsl:stylesheet>
Output:
<?xml version="1.0" encoding="UTF-8"?><TABLE border="1"><TR><td>name</TH><td>local</TH><td>URI</TH></TR><TR><TD>data</TD><TD>data</TD><TD/></TR><TR><TD>standard:id</TD><TD>id</TD><TD>http://www.w3.org/1999/XSL/Transform</TD></TR><TR><TD>standard:size</TD><TD>size</TD><TD>http://www.w3.org/1999/XSL/Transform</TD></TR><TR><TD>wbex:id</TD><TD>id</TD><TD>http://www.wbex.ru</TD></TR></TABLE>