I'm new to XSLT and can't figure out how to copy an attribute from a child tag to a new tag. I'm pretty sure it's a stupid beginner's mistake.
The input file is:
<?xml version="1.0" encoding="UTF-8"?> <navMap> <navPoint> <navLabel> <text>Chapter 1</text> </navLabel> <content src="Text/chapter01.html"/> </navPoint> </navMap>
The XSLT that I have so far is:
<?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>
<xsl:for-each select="navMap/navPoint">
<h1><span><xsl:value-of select="./content/@src" /></span><xsl:value-of select="./navLabel/text" /></h1>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
This'll generate:
<h1><span>Text/chapter01.html</span>Chapter 1</h1>
however, I need:
<h1 href="Text/chapter01.html">Chapter 1</h1>
How do I add a new href attribute to the h1 tag and copy the value of the src attribute of the content tag?
I tried:
<h1 href="<xsl:value-of select="./content/@src" />"><xsl:value-of select="./navLabel/text" /></h1>
but that generated a syntax error.