I’m trying to create links to the same document with my XML and XSLT. I’m trying to use generate-id() to create an index then anchors for the respective items.
problem is, the element name is not the same in the XML but i wish to link to it.
for example
XML:
<testresults>
<test testname="ComparisonResult">
<step stepname="Step1">
<result>true</result>
</step>
<step stepname="Step2" >
<result>true</result>
</step>
</test>
<step stepname="results" stepresult="true">
<drilldown>
<taskresults>
<testResults>
<test testname="ComparisonResult_Step1">
</test>
<test testname="ComparisonResult_Step2">
</test>
</testResults>
</taskresults>
</drilldown>
</step>
</testresults>
XSLT:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<font face="Arial" size="2">
<h4>Steps</h4>
<table border="1" bordercolor="#000000">
<tr bgcolor="#dccdc">
<th align="center">Task</th>
</tr>
<xsl:for-each select="testresults/test/step">
<tr>
<td bgcolor="#F2F5A9">
<a href="#{generate-id(@stepname)}">
<xsl:value-of select="@stepname" />
</a>
</td>
</tr>
</xsl:for-each>
</table>
<h2>Test Results</h2>
<xsl:for-each select="testresults/step/drilldown/taskresults/testResults/test">
<h3>
<a name="{generate-id(@testname)}">
<xsl:value-of select="@testname" />
</a>
</h3>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Please ignore any mistakes, this is a quick mockup but you should get an idea of what im trying to do. I can’t get it to link to the corresponding item. I.e Step1 to ComparisonResult_Step1.
Any ideas
Frankly I don’t see why you need generate-id, as long as those names are unique then doing e.g.
should suffice.
If you want to use generate-id then it only makes sense if you apply it to the same node.
[edit] If you want to use generate-id then add
<xsl:key name="k1" match="testresults/step/drilldown/taskresults/testResults/test" use="@testname"/>as a child of the xsl:stylesheet element, then change your code to e.g.