2013-06-21 3 views
2

XML 파일로 제공되는 데이터가 있습니다. XML을 HTML로 변환하는 XSLT도 제공되었습니다. lxml을 사용하여 변환을 수행 할 수 있지만 변환 후 일부 HTML 태그를 변경하려고합니다. 이 새로운 etree를 HtmlElements로 변환하여 .cssselect()와 같은 특정 메서드를 구체적으로 사용할 수있게하려면 어떻게해야합니까?lxml : XSLT를 통해 XML을 HTML로 변환하고 HtmlElements 가져 오기

+2

를? – akonsu

+0

아니요. 새로 만든 태그의 파일 이름을 가져 와서 새 html 파일에 Base64 코드화 할 수 있습니다. 그런 것들. – OozeMeister

+0

안녕하세요, xml 및 xslt를 html로 변환하는 데 사용하는 코드를 보내 주시겠습니까? 나는 인터넷에서 아무것도 찾을 수 없습니다. – Christopher

답변

0
>>> import lxml.etree 
>>> import lxml.html 
>>> 
>>> xmlstring = '''\ 
... <?xml version='1.0' encoding='ASCII'?> 
... <root><a class="here">link1</a><a class="there">link2</a></root> 
... ''' 
>>> root = lxml.etree.fromstring(xmlstring) 
>>> root.cssselect('a.here') 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
AttributeError: 'lxml.etree._Element' object has no attribute 'cssselect' 

lxml.etree.tostring(root) ->lxml.html.fromstring(..)

>>> root = lxml.html.fromstring(lxml.etree.tostring(root)) 
>>> root.cssselect('a.here') 
[<Element a at 0x2989308>] 

XML 출력을 얻을 : 쉽게 XSLT 코드를 변경하지 않는

>>> print lxml.etree.tostring(root, xml_declaration=True) 
<?xml version='1.0' encoding='ASCII'?> 
<root><a class="here">link1</a><a class="there">link2</a></root> 
+0

http://stackoverflow.com/questions/30662205/get-html-report- of-jetbrains- 명령 줄 도구 분석 –

관련 문제