[英]xml xslt 1.0 to 2.0 conversion
I am new to xml xslt xsl-fo and I made a xslt file in xslt 1.0.我是 xml xslt xsl-fo 的新手,我在 Z801F7201346B43CDZ8EE12 中制作了 xslt 文件。 I am trying to recreate this code in 2.0 but with group by functuin, from what I heard its easier but I can't get the hang of it.我正在尝试在 2.0 中重新创建此代码,但使用 group by functuin,据我所知它更容易,但我无法掌握它。 Where do I go wrong> Here is my xml file我在哪里 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>
Here is my working xslt 1.0 file这是我的工作 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>
And here is one of my atempts to transfer this xsl to xsl 2.0这是我将这个 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>
Any help is appreciated任何帮助表示赞赏
I am new to xml xslt xsl-fo and I made a xslt file in xslt 1.0.我是 xml xslt xsl-fo 的新手,我在 Z801F7201346B43CDZ8EE12 中制作了 xslt 文件。 I am trying to recreate this code in 2.0 but with group by functuin, from what I heard its easier but I can't get the hang of it.我正在尝试在 2.0 中重新创建此代码,但使用 group by functuin,据我所知它更容易,但我无法掌握它。 Where do I go wrong> Here is my xml file我在哪里 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>
Here is my working xslt 1.0 file这是我的工作 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>
And here is one of my atempts to transfer this xsl to xsl 2.0这是我将这个 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>
Any help is appreciated任何帮助表示赞赏
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.