创建按属性值排序的 table
create a table sorted by attribute value
我是 xslt 的新手,我一直在努力寻找解决方案,我需要创建一个 table,其中我的 xml 文档按属性“level”排序(niveau此处)然后按字母顺序排列
这是 xml 文档(如果您想知道,它是法语的)
<dico
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:noNamespaceSchemaLocation='dico.xsd'>
<mot niveau="2">arbre</mot>
<mot niveau="2">jeu</mot>
<mot niveau="3">essence</mot>
<mot niveau="5">convalescence</mot>
<mot niveau="5">mot-valise</mot>
<mot niveau="1">pain</mot>
<mot niveau="4">maintenance</mot>
</dico>
这是我的 xslt
<xsl:template match="/">
<html>
<head>
<title>Dictionnaire</title>
</head>
<body>
<xsl:apply-templates select="dico/mot">
<xsl:sort select="@niveau"/>
<xsl:sort select="."/>
</xsl:apply-templates>
</body>
</html>
</xsl:template>
<xsl:template match="mot">
<table border="4" cellspacing="4" cellpadding="2" width="80%">
<tr>
<colgroup>
<col style="width: 33%" />
<col style="width: 33%" />
<col style="width: 33%" />
</colgroup>
<td>
le mot est : <xsl:value-of select="."/>
</td>
<td>
niveau : <xsl:value-of select="@niveau"/>
</td>
</tr>
</table>
</xsl:template>`
请尝试以下 XSLT。
XSLT
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="html"/>
<xsl:template match="/dico">
<html>
<head>
<title>Dictionnaire</title>
</head>
<body>
<table border="4" cellspacing="4" cellpadding="2" width="80%">
<thead style="background-color: #4CAF50; color: white;">
<tr>
<th>mot</th>
<th>niveau</th>
</tr>
</thead>
<tbody>
<xsl:for-each select="mot">
<xsl:sort select="@niveau"/>
<xsl:sort select="."/>
<tr>
<td>le mot est : <xsl:value-of select="."/></td>
<td>niveau : <xsl:value-of select="@niveau"/></td>
</tr>
</xsl:for-each>
</tbody>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
我是 xslt 的新手,我一直在努力寻找解决方案,我需要创建一个 table,其中我的 xml 文档按属性“level”排序(niveau此处)然后按字母顺序排列
这是 xml 文档(如果您想知道,它是法语的)
<dico
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:noNamespaceSchemaLocation='dico.xsd'>
<mot niveau="2">arbre</mot>
<mot niveau="2">jeu</mot>
<mot niveau="3">essence</mot>
<mot niveau="5">convalescence</mot>
<mot niveau="5">mot-valise</mot>
<mot niveau="1">pain</mot>
<mot niveau="4">maintenance</mot>
</dico>
这是我的 xslt
<xsl:template match="/">
<html>
<head>
<title>Dictionnaire</title>
</head>
<body>
<xsl:apply-templates select="dico/mot">
<xsl:sort select="@niveau"/>
<xsl:sort select="."/>
</xsl:apply-templates>
</body>
</html>
</xsl:template>
<xsl:template match="mot">
<table border="4" cellspacing="4" cellpadding="2" width="80%">
<tr>
<colgroup>
<col style="width: 33%" />
<col style="width: 33%" />
<col style="width: 33%" />
</colgroup>
<td>
le mot est : <xsl:value-of select="."/>
</td>
<td>
niveau : <xsl:value-of select="@niveau"/>
</td>
</tr>
</table>
</xsl:template>`
请尝试以下 XSLT。
XSLT
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="html"/>
<xsl:template match="/dico">
<html>
<head>
<title>Dictionnaire</title>
</head>
<body>
<table border="4" cellspacing="4" cellpadding="2" width="80%">
<thead style="background-color: #4CAF50; color: white;">
<tr>
<th>mot</th>
<th>niveau</th>
</tr>
</thead>
<tbody>
<xsl:for-each select="mot">
<xsl:sort select="@niveau"/>
<xsl:sort select="."/>
<tr>
<td>le mot est : <xsl:value-of select="."/></td>
<td>niveau : <xsl:value-of select="@niveau"/></td>
</tr>
</xsl:for-each>
</tbody>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>