xml - Haskell: how to write a XSLT transform function without returning IO or arrows -
i want use hxt-xslt
transform string containing source xml based on second string containing xslt result xml string. basically, want function of type:
transf :: string -> string -> string transf xmlstr xsltstr = ...
i searched around, there isn't example xslt in hxt
documentation, , closest thing can find code this answer.
my problem example , library uses io
, arrows
heavily. want adapt code , "strip" io
, arrow
obtain plain transform function returns string
or maybe string
, don't know arrows.
i ask because need parse htmls embedded in csv file. having results in io
, arrows
makes difficult xslt code work rest of code.
based on @chi's comment on origin version of question, looked documentation, , closest thing can following code (by guessing , brute-forcing 3 out of 4 functions in text.xml.hxt.xslt.{compilation,application}
):
{-# language arrows, packageimports #-} import "hxt" text.xml.hxt.core import "hxt-xslt" text.xml.hxt.xslt.application import "hxt-xslt" text.xml.hxt.xslt.compilation import "hxt-xslt" text.xml.hxt.xslt.common --strxml = "<?xml version='1.0' encoding='utf-8'?>\n" strxml = "<catalog>\n <cd>\n <title>empire burlesque</title>\n <artist>bob dylan</artist>\n <country>usa</country>\n <company>columbia</company>\n <price>10.90</price>\n <year>1985</year>\n </cd>\n</catalog> " --strxslt = "<?xml version='1.0'?>\n\n" strxslt = "<xsl:stylesheet version='1.0'\nxmlns:xsl='http://www.w3.org/1999/xsl/transform'>\n\n<xsl:template match='/'>\n <html>\n <body>\n <h2>my cd collection</h2>\n <table border='1'>\n <tr bgcolor='#9acd32'>\n <th>title</th>\n <th>artist</th>\n </tr>\n <xsl:for-each select='catalog/cd'>\n <tr>\n <td><xsl:value-of select='title'/></td>\n <td><xsl:value-of select='artist'/></td>\n </tr>\n </xsl:for-each>\n </table>\n </body>\n </html>\n</xsl:template>\n\n</xsl:stylesheet> " applystylesheetstr strxslt strxml = let xml = head $ runla xread strxml xslt = assemblestylesheet (preparexsltdocument $head $ runla xread strxslt) [] in showtrees $ applystylesheet xslt xml
the example xml , xslt string came a w3schools tutorial.
so far, code without io, , arrows. , outputs:
*main> applystylesheetstr strxslt strxml "\n \n empire burlesque\n bob dylan\n usa\n columbia\n 10.90\n 1985\n \n"
i have few questions here:
i noticed
xread
used above cannot take standard xml headers<?xml version='1.0' encoding='utf-8'?>
. if included in xml or xslt, returns error. expected or using wrong?the correct output should html table follows, when using io/arrows code the answer:
<h2>my cd collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>title</th> <th>artist</th> </tr> <tr> <td>empire burlesque</td> <td>bob dylan</td> </tr> </table>
how should fix code pure xslt transform?
thanks.
Comments
Post a Comment