English 中文(简体)
如何在使用xslt后查阅结果xml文档
原标题:how to see the result xml files after using xslt
  • 时间:2011-11-04 14:13:47
  •  标签:
  • xml
  • perl
  • xslt

i 知道它似乎处于停滞状态,但如何能够看到结果xml? 例如,原xml:

<?xml-stylesheet type="text/xsl" href="root.xsl"?>
<root>   
<list>    
<a>aaaa</a>     
<b>bbbb</b>  
</list>
</root>

和相应的斜体:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" > 
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

  <xsl:param name="evalue">cccc</xsl:param>  
  <xsl:param name="ename">c</xsl:param>
  <xsl:output method="xml" encoding="utf-8"/>  
  <xsl:template match="@*|node()">    
    <xsl:copy>    
      <xsl:apply-templates select="@*|node()" />  
    </xsl:copy>
  </xsl:template>  
  <xsl:template match="list">   
    <xsl:copy>     
      <xsl:apply-templates/>    
      <xsl:if test="not(c)">    
        <xsl:element name="{$ename}"><xsl:value-of select="$evalue"/></xsl:element>    
      </xsl:if>   
    </xsl:copy> 
  </xsl:template>
</xsl:stylesheet>

并且希望看到结果:

<?xml-stylesheet type="text/xsl" href="root.xsl"?>
<root>   
<list>    
<a>aaaa</a>     
<b>bbbb</b> 
<c>cccc</c> 
</list>
</root>

不:

aaaabbbbcccc

i 审判 per: XML:XSLT

 use diagnostics;
 use XML::XSLT;
 my $xsl= root.xsl ;
 my $xmlfile= root.xml ;
 my $xslt = XML::XSLT->new ($xsl, warnings => 1);

 $xslt->transform ($xmlfile);
 print $xslt->toString;

 $xslt->dispose();

但它的 t工作,即以前从未使用过xslt,而是错了吗?

预先感谢。

最佳回答

(废除所有旧的申诉)。

由此,我可以通过使用某些特性来做到这一点。 因此,它打破了案文节点值(至少似乎)。 因此,我就是这样做的。 我修改了你的XML。

  ...
  <xsl:param name="evalue" select="cccc"/>  
  <xsl:param name="ename"  select="c"/>
  ...

之后又认识到,我正在收到一份文件fragment(XML:DOM:DocumentFragment <>code>)作为xslt->result_document, 我使用文件所有人,并将印刷线改为:

print " --- ", $xslt->result_document->getOwnerDocument->toString, " --- ";

然而,它喜欢老的文件。 而且,我确实建议使用其他东西,从2005-2006年开始,它有开放和新的泡沫:。 最后解决的 b也是6年前:

我在守则中越多,我越看错了。


你们的意思是“做不到工作”! 你们是否像我一样得到 trace的追踪? 从我所能看到的(在我所看到的0.48版本中)来看,这一模块已经放弃了认识,很可能是出于良好的理由。

  • The only way it stores an XML document is open_xml which is called only in open_project or transform.
  • open_project is not called internally, and transform is only called by serve which is not called internally

然而,

  • new always calls open_xsl
  • Which always calls __preprocess_stylesheet
  • Which always calls __extract_top_level_variables
  • Which attempts to parse the variable and param elements and if that element doesn t have a select attribute (which you don t have) it tries to call xml_document and then its createDocumentFragment method. 然而,it hasn t (as far as I can see) allowed you to set the xml_document. It probably meant to call xsl_document. But by the time it gets here, it s already stored an XML::DOM::Element NOT the Document as a mandatory part of __get_stylesheet called all the time from __preprocess_stylesheet before __extract_top_level_variables was called.

So when I left the call as xml_document it told me:
Can t call method "createDocumentFragment" on an undefined value. But if you assign that to the more correct xsl_document field you get told
Can t locate object method "createDocumentFragment" via package "XML::DOM::Element".

我认为,XML:LibXSLT远比标准要高得多。

问题回答

暂无回答




相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...