Rrendering一個XML :: XPath的:: NODESET我需要呈現使用XSLT模板通過XML::XPath
使用XSLT模板與XML ::
my $source = XML::LibXML->load_xml(location => 'xml/animals.xml');
my $nodeset = $source->find('//area[@id="01"]');
發現了一個節點集與XML::LibXSLT
:
my $xslt = XML::LibXSLT->new();
my $style_doc = XML::LibXML->load_xml(location=>'xml/animal_template.xsl', no_cdata=>1);
my $stylesheet = $xslt->parse_stylesheet($style_doc);
但我不能簡單地給節點集到$stylesheet->transform()
:
my $results = $stylesheet->transform($nodeset);
,因爲變換期望有一個XML::LibXML::Document
對象,而不是XML::XPath::NodeSet
。
我該怎麼辦?有沒有辦法從XML::XPath::NodeSet
創建XML::LibXML::Document
?
或者也許給XSLT模板一個變量,所以我不必用XPath找到節點?
使用解決 $ stylesheet->變換($文檔,XML :: ::的libxslt xpath_to_string( PARAM => 「字符串」 )); 寫在http://search.cpan.org/~shlomif/XML-LibXSLT-1.77/LibXSLT.pm – qwertoyo
我看不出如何解決您的問題。你是通過'$ doc'傳遞的?以前你只有一個'XML :: XPath :: NodeSet'對象提供。 – Borodin
對不起,它沒有工作。 – qwertoyo