开发者

ASP.NET, XSLT, extracting values from a CDATA section

开发者 https://www.devze.com 2022-12-26 13:41 出处:网络
i have a small problem i have xome xml with a cdata section. This CDATA section contains fragments of HTMl. I would like to extract some of the data inside this CDATA element. Right now i have a XSLT

i have a small problem i have xome xml with a cdata section. This CDATA section contains fragments of HTMl. I would like to extract some of the data inside this CDATA element. Right now i have a XSLT transformation that outputs the rest of the document as HTMl, but i need only a small part of th开发者_如何学Ce CDATA HTML, not the entire part - e.g. a my Title tag. How to do this?


XSLT won't read the CDATA section as anything other than text. You'll need to pre-parse your data before handing it over to XSLT. You could use a preparsing script (written in Python, PHP, Perl, VB, whatever) and then do one of (but not limited to) the following:

  • remove the CDATA tags and allow XSLT to handle the undesired content
  • move the <title> tag to a XSLT accesible place outside the CDATA tags
  • maybe using Beautiful Soup in Python (or a cthulhu-inducing regex) get the desired value out of the CDATA section, and pass the desired value as a parameter to XSLT
0

精彩评论

暂无评论...
验证码 换一张
取 消