XSLT Transformation Not Preserving Attributes in Output XML - Unexpected Loss of Data
I've been struggling with this for a few days now and could really use some help... I'm currently facing a challenge with XSLT transformations where certain attributes in my input XML are being lost in the output. I'm using XSLT 1.0 with Saxon 9.9 and my input XML looks like this: ```xml <books> <book id="1" genre="fiction"> <title>1984</title> <author>George Orwell</author> </book> <book id="2" genre="non-fiction"> <title>Sapiens</title> <author>Yuval Noah Harari</author> </book> </books> ``` My XSLT file is intended to transform this into a format where I want to include only the title and author, but I'm also trying to preserve the `genre` attribute. Here's the XSLT snippet I've written: ```xslt <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/> <xsl:template match="book"> <newbook genre="{@genre}"> <title><xsl:value-of select="title"/></title> <author><xsl:value-of select="author"/></author> </newbook> </xsl:template> </xsl:stylesheet> ``` However, when I run the transformation, the output XML looks like this: ```xml <newbook> <title>1984</title> <author>George Orwell</author> </newbook> ``` As you can see, the `genre` attribute is missing from the output. I've also tried using `<xsl:copy>` to see if that would help, but I still faced the same issue. My concern is that this behavior could be related to the way I'm structuring the output. I've reviewed the XSLT and am confident that the syntax is correct. Additionally, I've checked that the `genre` attribute is indeed present in the input XML. What could be causing this attribute to not appear in the output? Are there any known limitations or best practices in XSLT 1.0 regarding attribute handling that I might be overlooking? Any insights or suggestions would be greatly appreciated. This is part of a larger CLI tool I'm building. Has anyone else encountered this? How would you solve this?