如何从匹配中排除一个名称空间前缀?

时间:2015-12-09 10:45:18

标签: xslt

使用xslt 1.0 我想从匹配中排除pma:database和pma:table,我添加了exclude-result-prefixes但它似乎没有效果。

我不需要转换xml的配置部分。

的xml:

<?xml version="1.0" encoding="utf-8"?>
<!--
- phpMyAdmin XML Dump
- version 4.1.7
- http://www.phpmyadmin.net
-
- Host: localhost
- Generation Time: Dic 07, 2015 alle 16:57
- Versione del server: 5.1.71-community-log
- PHP Version: 5.3.10
-->

<pma_xml_export version="1.0" xmlns:pma="http://www.phpmyadmin.net/some_doc_url/">
<!--
- Structure schemas
-->
<pma:structure_schemas>
    <pma:database name="my_professioneslot" collation="latin1_swedish_ci" charset="latin1">
        <pma:table name="Slots">
            CREATE TABLE `Slots` (
              `ID` int(11) NOT NULL,
              `IdProduttore` int(11) NOT NULL,
              `Scheda` varchar(50) NOT NULL,
              `NomeCommerciale` varchar(50) NOT NULL,
              `Produttore2` int(11) NOT NULL,
              `CodiceModello` varchar(50) NOT NULL,
              `PercMinima` int(11) NOT NULL,
              `Ciclo` int(11) NOT NULL,
              PRIMARY KEY (`ID`)
            ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
        </pma:table>
    </pma:database>
</pma:structure_schemas>

<!--
- Database: 'my_professioneslot'
-->
<database name="my_professioneslot">
    <!-- Tabella Slots -->
    <table name="Slots">
        <column name="ID">1</column>
        <column name="IdProduttore">1</column>
        <column name="Scheda">GOOD LUCK ULTIMATE</column>
        <column name="NomeCommerciale">CASINO' GOOD LUCK ULTIMATE</column>
        <column name="Produttore2">0</column>
        <column name="CodiceModello">776870592765183</column>
        <column name="PercMinima">75</column>
        <column name="Ciclo">30000</column>
    </table>
    <table name="Slots">
        <column name="ID">2</column>
        <column name="IdProduttore">1</column>
        <column name="Scheda">MEGA DOBLONE</column>
        <column name="NomeCommerciale">CASINO' MEGA DOBLONE</column>
        <column name="Produttore2">0</column>
        <column name="CodiceModello">776870592865184</column>
        <column name="PercMinima">75</column>
        <column name="Ciclo">30000</column>
    </table>

的xsl:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:pma="http://www.phpmyadmin.net/some_doc_url/"
exclude-result-prefixes="msxsl pma">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="database">
  <xsl:element name="produttori">
  <xsl:for-each select="table">
    <xsl:element name="produttore" >
      <xsl:attribute name="id">
        <xsl:value-of select="column[@name='ID']"/>
      </xsl:attribute>
        <xsl:value-of select="column[@name='Descrizione']"/>
    </xsl:element>
    </xsl:for-each>
  </xsl:element>
</xsl:template>

结果:

            CREATE TABLE `Slots` (
              `ID` int(11) NOT NULL,
              `IdProduttore` int(11) NOT NULL,
              `Scheda` varchar(50) NOT NULL,
              `NomeCommerciale` varchar(50) NOT NULL,
              `Produttore2` int(11) NOT NULL,
              `CodiceModello` varchar(50) NOT NULL,
              `PercMinima` int(11) NOT NULL,
              `Ciclo` int(11) NOT NULL,
              PRIMARY KEY (`ID`)
            ) ENGINE=MyISAM DEFAULT CHARSET=latin1;





<produttori><produttore id="1"></produttore><produttore id="2"></produttore></produttori>

1 个答案:

答案 0 :(得分:1)

exclude-result-prefixes仅在未使用前缀时从输出XML中排除前缀声明。如果要删除某些元素,即某些命名空间中的元素,可以使用与此元素匹配的空模板,例如:

<xsl:template match="pma:*"/>

上面很好地删除了前缀pma

引用的命名空间中的所有元素