Need help to convert following html to csv with meta tags of html

淺唱寂寞╮ 提交于 2020-01-17 03:04:06

问题


<html>
<head>
<title>My Headline</title>
<meta name="targetUrl" value="xyz.html?sym=abc"/>
<meta name="summary" value="A & B"/>
</head>
<body>
abc abc, pqr, xyz, rst tsd, prrrr, qqqqqqq, oooooo, opop opop, rtrttrt rtrtrtrt
</body>
</html>

The body tag should be changed to csv so the output should be like this :

abc abc, pqr, xyz, rst tsd, prrrr, qqqqqqq, oooooo, opop opop, rtrttrt rtrtrtrt

if i try @Jim's solution

parsing exception occurs for meta tags as they have special characters


回答1:


Here's an XSLT1 solution

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="text"/>
  <xsl:template match="@*|node()"><xsl:apply-templates select="@*|node()"/></xsl:template>
  <xsl:template match="body"><xsl:value-of select="text()"/></xsl:template>
</xsl:stylesheet>

Note that since your input contains a newline before and after the data, it will be written to the output as well, resulting in a blank first and lasst line.



来源:https://stackoverflow.com/questions/5807632/need-help-to-convert-following-html-to-csv-with-meta-tags-of-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!