使用xml文档中的Xslt创建锚定
我正在尝试使用XSLT1.0从xml文档创建html。在xml文档中,有客户,在一些客户的name属性中有see XXXX信息 这是xml文档使用xml文档中的Xslt创建锚定,xml,xslt,anchor,Xml,Xslt,Anchor,我正在尝试使用XSLT1.0从xml文档创建html。在xml文档中,有客户,在一些客户的name属性中有see XXXX信息 这是xml文档 <?xml version="1.0" encoding="UTF-8"?> <customers> <customer name="Adam Dev" category="A1" phone="1234543" /> <customer name="Jerry Sngiler (see Matt
<?xml version="1.0" encoding="UTF-8"?>
<customers>
<customer name="Adam Dev" category="A1" phone="1234543" />
<customer name="Jerry Sngiler (see Matt Pcneiv)" category="" phone="" />
<customer name="Heid Schwan" category="B1" phone="121257456" />
<customer name="Matt Pcneiv" category="A2" phone="65656565" />
<customer name="John Lombak" category="A2" phone="787878787" />
<customer name="April Ozil (see Heid Schwan)" category="" phone="" />
<customer name="Terry Hill" category="B1" phone="1212121212" />
</customers>
我想为xml文档中相关xml节点的name属性创建锚定,如下所示。我的意思是,当用户单击第二个节点上的Matt Pcneiv时,页面跳转到4.node上的Matt Pcneiv。同样,当用户单击6.node上的Heid Schwan时,页面跳转到3.node上的Heid Schwan
<html>
<head>
<style>
table,th,td
{
border:1px solid black;
border-collapse:collapse;
}
th,td
{
padding:5px;
}
</style>
</head>
<body>
<table style="width:600px">
<tr>
<th>Name</th>
<th>Category</th>
<th>Phone</th>
</tr>
<tr>
<td>Adam Dev</td>
<td>A1</td>
<td>1234543</td>
</tr>
<tr>
**<td>Jerry Sngiler (see <a href="#C1">Matt Pcneiv</a>)</td>**
<td></td>
<td></td>
</tr>
<tr>
**<td><a id="C2">Heid Schwan</a></td>**
<td>B1</td>
<td>121257456</td>
</tr>
<tr>
**<td><a id="C1">Matt Pcneiv</a></td>**
<td>A2</td>
<td>65656565</td>
</tr>
<tr>
<td>John Lombak</td>
<td>A2</td>
<td>787878787</td>
</tr>
<tr>
**<td>April Ozil (see <a href="#C2">Heid Schwan</a>)</td>**
<td></td>
<td></td>
</tr>
<tr>
<td>Terry Hill</td>
<td>B1</td>
<td>1212121212</td>
</tr>
</table>
</body>
</html>
如何使用xsl实现这一点?如果您能帮助我,我将不胜感激。
谢谢。那好吧。第一件事:设计输入XML的人都是白痴。首先,您可以使用结构化数据工具;你为什么要把两个名字塞进一个插槽?另一方面,有一天肯定会有两个同名的顾客 这样一来,您需要在这里提取引用的名称,并将其用作链接到被引用人的锚的键:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:key name="customer-by-name" match="customer" use="@name" />
<xsl:template match="/">
<table>
<tr>
<th>Name</th>
<th>Category</th>
<th>Phone</th>
</tr>
<xsl:apply-templates select="customers/customer"/>
</table>
</xsl:template>
<xsl:template match="customer">
<tr>
<td><a id="{generate-id()}"><xsl:value-of select="@name"/></a></td>
<td><xsl:value-of select="@category"/></td>
<td><xsl:value-of select="@phone"/></td>
</tr>
</xsl:template>
<xsl:template match="customer[contains(@name, ' (see ')]">
<xsl:variable name="ref-name" select="substring-before(substring-after(@name, ' (see '), ')')" />
<tr>
<td>
<xsl:value-of select="substring-before(@name, ' (see ')"/>
<xsl:text> (see </xsl:text>
<a href="#{generate-id(key('customer-by-name', $ref-name))}"><xsl:value-of select="$ref-name"/></a>
<xsl:text>)</xsl:text>
</td>
<td><xsl:value-of select="@category"/></td>
<td><xsl:value-of select="@phone"/></td>
</tr>
</xsl:template>
</xsl:stylesheet>
你不想填写类别和电话号码并删除参考资料吗?我会的,但这不是我可以做的决定,谢谢。谢谢你,迈克尔,谢谢你的解决方案。您认为可以在您的解决方案中添加类别节点上的分组吗?如何将Muenchian方法应用于您的解决方案?将两者结合起来应该不会有任何问题。