I have a XML document and I need pass it to CSV with XSL. I managed to perform this process, but I have problems with special characters, ie "& quot;, & amp; ... I need you to make the change these characters are not changed and remain represented in the same way. I have the following:
XML file
<?xml version="1.0" encoding="UTF-8"?> <pwlist> <pwentry> <group>General</group> <title>Sample Entry</title> <username>Greg</username> <url>http://www.web.com</url> <password>sVoVd2HohmC7hpKYV5Bs</password> <notes>This entry is stored in the 'General' group.</notes> <uuid>4d9a9420ac7c4a8ae688762eac8871a9</uuid> <image>0</image> <creationtime>2006-12-31T11:52:01</creationtime> <lastmodtime>2006-12-31T11:52:01</lastmodtime> <lastaccesstime>2006-12-31T11:52:01</lastaccesstime> <expiretime expires="false">2999-12-28T23:59:59</expiretime> </pwentry> <pwentry> <group tree="General">Windows</group> <title>Sample Entry #2</title> <username>michael@web.com</username> <url>http://www.web.com</url> <password>L2shNNvQLmOWug68Rz2V</password> <notes>This entry is stored in the 'Windows' subgroup of the 'General' group.</notes> <uuid>bddda53fad29037bba34e7e42923c676</uuid> <image>0</image> <creationtime>2006-12-31T11:52:38</creationtime> <lastmodtime>2006-12-31T11:52:38</lastmodtime> <lastaccesstime>2006-12-31T11:52:38</lastaccesstime> <expiretime expires="false">2999-12-28T23:59:59</expiretime> </pwentry> <pwentry> <group tree="General">Windows</group> <title>Expiring Entry</title> <username>me@website.org</username> <url>http://www.website.org</url> <password>USYbBOdTjaerrN/3l0VK</password> <notes>This entry expires on 28.12.2008, at 23:59:59.</notes> <uuid>c2674112d67f2787e822d845cde52858</uuid> <image>0</image> <creationtime>2006-12-31T11:53:38</creationtime> <lastmodtime>2006-12-31T11:53:38</lastmodtime> <lastaccesstime>2006-12-31T11:53:38</lastaccesstime> <expiretime expires="true">2008-12-28T23:59:59</expiretime> </pwentry> <pwentry> <group tree="General">Windows</group> <title>Special Characters Test</title> <username>!"§$%&/()=?`´²³{[]}\</username> <url></url> <password>öüäÖÜÄß<>@€µ®"«</password> <notes>The user name and password fields contain special characters.</notes> <uuid>6a4aae3134cb7b7d550d0bb7c98bc203</uuid> <image>34</image> <creationtime>2006-12-31T11:55:57</creationtime> <lastmodtime>2006-12-31T11:56:06</lastmodtime> <lastaccesstime>2006-12-31T11:56:06</lastaccesstime> <expiretime expires="true">2008-12-28T23:59:59</expiretime> </pwentry> <pwentry> <group tree="General">Windows</group> <title>Multi-Line Test</title> <username>user@website.com</username> <url>http://www.website.com</url> <password>v9ffIWkd/jPw/GPLFViW</password> <notes>This is a multi-line comment. This is a multi-line comment. This is a multi-line comment. This is a multi-line comment. This is a multi-line comment. This is a multi-line comment.</notes> <uuid>3d4fe2dc30d4ef0b62da6c7bf85e04ba</uuid> <image>0</image> <creationtime>2006-12-31T11:56:49</creationtime> <lastmodtime>2006-12-31T11:56:49</lastmodtime> <lastaccesstime>2006-12-31T11:56:49</lastaccesstime> <expiretime expires="false">2999-12-28T23:59:59</expiretime> </pwentry> </pwlist>
XSL file:
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" omit-xml-declaration="yes" byte-order-mark="no" indent="no" /> <xsl:variable name="delimiter" select="','" /> <xsl:variable name="fieldArray" > <field>group</field> <field>title</field> <field>username</field> <field>url</field> <field>password</field> <field>notes</field> <field>uuid</field> <field>image</field> <field>creationtime</field> <field>lastmodtime</field> <field>lastaccesstime</field> <field>expiretime</field> </xsl:variable> <xsl:param name="fields" select="document('')/*/xsl:variable[@name='fieldArray']/*"/> <xsl:template match="/"> <xsl:for-each select="$fields"> <xsl:if test="position() !=1"> <xsl:value-of select="$delimiter"/> </xsl:if> <xsl:value-of select="." /> </xsl:for-each> <xsl:text>
</xsl:text> <xsl:apply-templates select="pwlist/pwentry"/> </xsl:template> <xsl:template match="pwentry"> <xsl:variable name="currNode" select="." /> <xsl:for-each select="$fields"> <xsl:if test="position() !=1"> <xsl:value-of select="$delimiter"/> </xsl:if> <xsl:text>"</xsl:text> <xsl:value-of select="$currNode/*[name() = current()]" /> <xsl:text>"</xsl:text> </xsl:for-each> <xsl:text>
</xsl:text> </xsl:template> </xsl:stylesheet>
I tried disable-output-escaping="no" but doesn't work, can someone help me? Thanks!
No comments:
Post a Comment