繁体   English   中英

xml xslt 1.0到2.0的转换

[英]xml xslt 1.0 to 2.0 conversion

我是 xml xslt xsl-fo 的新手,我在 Z801F7201346B43CDZ8EE12 中制作了 xslt 文件。 我正在尝试在 2.0 中重新创建此代码,但使用 group by functuin,据我所知它更容易,但我无法掌握它。 我在哪里 go 错了> 这是我的 xml 文件

<employees>

    <employee id="1">
        <first_name>Andrei Ionut</first_name>
        <last_name>Socol </last_name>
        <nationality>Romanian</nationality>
        <phone>0736354567</phone>
    </employee>
    
        <employee id="2">
        <first_name>Raluca </first_name>
        <last_name>Filip </last_name>
        <nationality>Romanian</nationality>
        <phone>0736323567</phone>
    </employee>


    <employee id="3">
        <first_name>Dinu Constantin</first_name>
        <last_name>Socol </last_name>
        <nationality>Romanian</nationality>
        <phone>0731254567</phone>
    </employee>


    <employee id="4">
        <first_name>Anca </first_name>
        <last_name>Anghelescu </last_name>
        <nationality>Romanian</nationality>
        <phone>0731258507</phone>
    </employee>


    <employee id="5">
        <first_name> Yasser</first_name>
        <last_name>Alkadah</last_name>
        <nationality>Syrian</nationality>
        <phone>0731254599</phone>
    </employee>


    <employee id="6">
        <first_name>Thomas </first_name>
        <last_name>Keller </last_name>
        <nationality>German</nationality>
        <phone>0731254367</phone>
    </employee>




    <employee id="7">
        <first_name>Marius Eugen </first_name>
        <last_name>Stochita </last_name>
        <nationality>Romanian</nationality>
        <phone>0731154367</phone>
    </employee>
</employees>

这是我的工作 xslt 1.0 文件

   <?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:key name="nationality-search" match="employee" use="nationality"/>

<xsl:output method="html" indent="yes"/>
<xsl:key name="person-nationality" match="/employees/employee" use="nationality" />
  
  <xsl:template match="/employees">
    <xsl:apply-templates select="employee[generate-id() = generate-id(key('person-nationality', nationality)[1])]"/>
  </xsl:template>

  <xsl:template match="employee">
<html>
<body>

    <h2><i>Nationality: </i><xsl:value-of select="nationality"/></h2>

    <table border="1">
    <tr bgcolor="#9acd28">
        <th>First Name</th>
        <th>Last Name</th>
        <th>Phone</th>
      </tr>
      <xsl:for-each select="key('person-nationality', nationality)">
        <tr>
          <td><xsl:value-of select="first_name"/></td>
          <td><xsl:value-of select="last_name"/></td>
          <td><xsl:value-of select="phone"/></td>
        </tr>
      </xsl:for-each>
    </table>
    </body>
</html>
    </xsl:template>
    </xsl:stylesheet>

这是我将这个 xsl 转移到 xsl 2.0 的尝试之一

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
   <xsl:template match="/employees">
 
         <xsl:for-each-group select="/employees/employee" group-by="@nationality">
                  <html>        
                    <body>

                <key>
                <h2><i>Nationality: </i>  <xsl:value-of select="current-grouping-key()"></xsl:value-of> </h2>
               </key>
                        <table border="1">
                            <tr bgcolor="#9acd28">
                                <th>First Name</th>
                                <th>Last Name</th>
                                <th>Phone</th>
                              </tr>
                                  
                            <xsl:for-each select="current-group()">
                                <tr>
                   <td><xsl:value-of select="first_name"></xsl:value-of></td>
                   <td> <xsl:value-of select="last_name"></xsl:value-of></td>
                   <td> <xsl:value-of select="phone"></xsl:value-of></td>
                                </tr>
                              </xsl:for-each>
            </table>
            </body>
        </html>
         </xsl:for-each-group>
   </xsl:template>
</xsl:stylesheet>

任何帮助表示赞赏

我是 xml xslt xsl-fo 的新手,我在 Z801F7201346B43CDZ8EE12 中制作了 xslt 文件。 我正在尝试在 2.0 中重新创建此代码,但使用 group by functuin,据我所知它更容易,但我无法掌握它。 我在哪里 go 错了> 这是我的 xml 文件

<employees>

    <employee id="1">
        <first_name>Andrei Ionut</first_name>
        <last_name>Socol </last_name>
        <nationality>Romanian</nationality>
        <phone>0736354567</phone>
    </employee>
    
        <employee id="2">
        <first_name>Raluca </first_name>
        <last_name>Filip </last_name>
        <nationality>Romanian</nationality>
        <phone>0736323567</phone>
    </employee>


    <employee id="3">
        <first_name>Dinu Constantin</first_name>
        <last_name>Socol </last_name>
        <nationality>Romanian</nationality>
        <phone>0731254567</phone>
    </employee>


    <employee id="4">
        <first_name>Anca </first_name>
        <last_name>Anghelescu </last_name>
        <nationality>Romanian</nationality>
        <phone>0731258507</phone>
    </employee>


    <employee id="5">
        <first_name> Yasser</first_name>
        <last_name>Alkadah</last_name>
        <nationality>Syrian</nationality>
        <phone>0731254599</phone>
    </employee>


    <employee id="6">
        <first_name>Thomas </first_name>
        <last_name>Keller </last_name>
        <nationality>German</nationality>
        <phone>0731254367</phone>
    </employee>




    <employee id="7">
        <first_name>Marius Eugen </first_name>
        <last_name>Stochita </last_name>
        <nationality>Romanian</nationality>
        <phone>0731154367</phone>
    </employee>
</employees>

这是我的工作 xslt 1.0 文件

   <?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:key name="nationality-search" match="employee" use="nationality"/>

<xsl:output method="html" indent="yes"/>
<xsl:key name="person-nationality" match="/employees/employee" use="nationality" />
  
  <xsl:template match="/employees">
    <xsl:apply-templates select="employee[generate-id() = generate-id(key('person-nationality', nationality)[1])]"/>
  </xsl:template>

  <xsl:template match="employee">
<html>
<body>

    <h2><i>Nationality: </i><xsl:value-of select="nationality"/></h2>

    <table border="1">
    <tr bgcolor="#9acd28">
        <th>First Name</th>
        <th>Last Name</th>
        <th>Phone</th>
      </tr>
      <xsl:for-each select="key('person-nationality', nationality)">
        <tr>
          <td><xsl:value-of select="first_name"/></td>
          <td><xsl:value-of select="last_name"/></td>
          <td><xsl:value-of select="phone"/></td>
        </tr>
      </xsl:for-each>
    </table>
    </body>
</html>
    </xsl:template>
    </xsl:stylesheet>

这是我将这个 xsl 转移到 xsl 2.0 的尝试之一

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
   <xsl:template match="/employees">
 
         <xsl:for-each-group select="/employees/employee" group-by="@nationality">
                  <html>        
                    <body>

                <key>
                <h2><i>Nationality: </i>  <xsl:value-of select="current-grouping-key()"></xsl:value-of> </h2>
               </key>
                        <table border="1">
                            <tr bgcolor="#9acd28">
                                <th>First Name</th>
                                <th>Last Name</th>
                                <th>Phone</th>
                              </tr>
                                  
                            <xsl:for-each select="current-group()">
                                <tr>
                   <td><xsl:value-of select="first_name"></xsl:value-of></td>
                   <td> <xsl:value-of select="last_name"></xsl:value-of></td>
                   <td> <xsl:value-of select="phone"></xsl:value-of></td>
                                </tr>
                              </xsl:for-each>
            </table>
            </body>
        </html>
         </xsl:for-each-group>
   </xsl:template>
</xsl:stylesheet>

任何帮助表示赞赏

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM