[英]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.