XML-XSLT

 view release on metacpan or  search on metacpan

ChangeLog  view on Meta::CPAN

<name>examples/XSLT.xml</name>
<cvsstate>Exp</cvsstate>
<revision>1.1</revision>
</file>
<file>
<name>examples/XSLT.xsl</name>
<cvsstate>Exp</cvsstate>
<revision>1.1</revision>
</file>
<file>
<name>t/cdata_sect.t</name>
<cvsstate>Exp</cvsstate>
<revision>1.4</revision>
</file>
<msg>* Added the modules own documentation as an example</msg>
</entry>

<entry>
<date>2002-01-13</date>
<weekday>Sunday</weekday>
<time>10:35</time>

ChangeLog  view on Meta::CPAN

<name>lib/XML/XSLT.pm</name>
<cvsstate>Exp</cvsstate>
<revision>1.16</revision>
</file>
<file>
<name>t/attributes.t</name>
<cvsstate>Exp</cvsstate>
<revision>1.3</revision>
</file>
<file>
<name>t/cdata_sect.t</name>
<cvsstate>Exp</cvsstate>
<revision>1.3</revision>
</file>
<file>
<name>t/forward.t</name>
<cvsstate>Exp</cvsstate>
<revision>1.2</revision>
</file>
<file>
<name>t/output.t</name>

ChangeLog  view on Meta::CPAN

* Stylesheet whitespace stripping as per spec and altered tests ...</msg>
</entry>

<entry>
<date>2002-01-08</date>
<weekday>Tuesday</weekday>
<time>10:16</time>
<isoDate>2002-01-08T10:16:54Z</isoDate>
<author>gellyfish</author>
<file>
<name>t/cdata_sect.t</name>
<cvsstate>Exp</cvsstate>
<revision>1.2</revision>
</file>
<msg>foo'd up the t/cdata_sect.t</msg>
</entry>

<entry>
<date>2002-01-08</date>
<weekday>Tuesday</weekday>
<time>10:11</time>
<isoDate>2002-01-08T10:11:46Z</isoDate>
<author>gellyfish</author>
<file>
<name>MANIFEST</name>

ChangeLog  view on Meta::CPAN

<name>lib/XML/XSLT.pm</name>
<cvsstate>Exp</cvsstate>
<revision>1.15</revision>
</file>
<file>
<name>t/call_template.t</name>
<cvsstate>Exp</cvsstate>
<revision>1.1</revision>
</file>
<file>
<name>t/cdata_sect.t</name>
<cvsstate>Exp</cvsstate>
<revision>1.1</revision>
</file>
<file>
<name>t/spec_examples.t</name>
<cvsstate>Exp</cvsstate>
<revision>1.2</revision>
</file>
<msg>* First cut at cdata-section-element
* test for above</msg>
</entry>

<entry>
<date>2001-12-24</date>
<weekday>Monday</weekday>
<time>16:00</time>
<isoDate>2001-12-24T16:00:19Z</isoDate>
<author>gellyfish</author>
<file>

MANIFEST  view on Meta::CPAN

examples/test.dtd
examples/test.xml
examples/test.xsl
examples/test2.xml
examples/test2.xsl
examples/xmlspec.xsl
examples/xpath.xsl
examples/xslt.xsl
t/attributes.t
t/call_template.t
t/cdata_sect.t
t/comment.t
t/copy.t
t/doe.t
t/features.t
t/for-each.t
t/forward.t
t/output.t
t/params.t
t/pattern.t
t/pi.t

examples/REC-xml-19980210.xml  view on Meta::CPAN

The target names "<code>XML</code>", "<code>xml</code>", and so on are
reserved for standardization in this or future versions of this
specification.
The 
XML <termref def='dt-notation'>Notation</termref> mechanism
may be used for
formal declaration of PI targets.
</p>
</div2>
 
<div2 id='sec-cdata-sect'>
<head>CDATA Sections</head>
 
<p><termdef id="dt-cdsection" term="CDATA Section"><term>CDATA sections</term>
may occur 
anywhere character data may occur; they are
used to escape blocks of text containing characters which would
otherwise be recognized as markup.  CDATA sections begin with the
string "<code>&lt;![CDATA[</code>" and end with the string
"<code>]]&gt;</code>":
<scrap lang="ebnf">

examples/REC-xslt-19991116.xml  view on Meta::CPAN

  <e:attribute name="standalone">
    <e:constant value="yes"/>
    <e:constant value="no"/>
  </e:attribute>
  <e:attribute name="doctype-public">
    <e:data-type name="string"/>
  </e:attribute>
  <e:attribute name="doctype-system">
    <e:data-type name="string"/>
  </e:attribute>
  <e:attribute name="cdata-section-elements">
    <e:data-type name="qnames"/>
  </e:attribute>
  <e:attribute name="indent">
    <e:constant value="yes"/>
    <e:constant value="no"/>
  </e:attribute>
  <e:attribute name="media-type">
    <e:data-type name="string"/>
  </e:attribute>
  <e:empty/>

examples/REC-xslt-19991116.xml  view on Meta::CPAN

to be used in the document type declaration</p></item>

<item><p><code>omit-xml-declaration</code> specifies whether the XSLT
processor should output an XML declaration; the value must be
<code>yes</code> or <code>no</code></p></item>

<item><p><code>standalone</code> specifies whether the XSLT processor
should output a standalone document declaration; the value must be
<code>yes</code> or <code>no</code></p></item>

<item><p><code>cdata-section-elements</code> specifies a list of the
names of elements whose text node children should be output using
CDATA sections</p></item>

</ulist>

<p>The detailed semantics of each attribute will be described
separately for each output method for which it is applicable.  If the
semantics of an attribute are not described for an output method, then
it is not applicable to that output method.</p>

<p>A stylesheet may contain multiple <code>xsl:output</code> elements
and may include or import stylesheets that also contain
<code>xsl:output</code> elements.  All the <code>xsl:output</code>
elements occurring in a stylesheet are merged into a single effective
<code>xsl:output</code> element. For the
<code>cdata-section-elements</code> attribute, the effective value is
the union of the specified values.  For other attributes, the
effective value is the specified value with the highest <termref
def="dt-import-precedence">import precedence</termref>. It is an error
if there is more than one such value for an attribute.  An XSLT
processor may signal the error; if it does not signal the error, if
should recover by using the value that occurs last in the stylesheet.
The values of attributes are defaulted after the
<code>xsl:output</code> elements have been merged; different output
methods may have different default values for an attribute.</p>

examples/REC-xslt-19991116.xml  view on Meta::CPAN

algorithm to output additional whitespace that ensures that the result
if whitespace were to be stripped from the output using the process
described in <specref ref="strip"/> with the set of
whitespace-preserving elements consisting of just
<code>xsl:text</code> would be the same when additional whitespace is
output as when additional whitespace is not output.</p>

<note><p>It is usually not safe to use <code>indent="yes"</code> with
document types that include element types with mixed content.</p></note>

<p>The <code>cdata-section-elements</code> attribute contains a
whitespace-separated list of <xnt
href="&XMLNames;#NT-QName">QName</xnt>s.  Each <xnt
href="&XMLNames;#NT-QName">QName</xnt> is expanded into an
expanded-name using the namespace declarations in effect on the
<code>xsl:output</code> element in which the <xnt
href="&XMLNames;#NT-QName">QName</xnt> occurs; if there is a default
namespace, it is used for <xnt href="&XMLNames;#NT-QName">QName</xnt>s
that do not have a prefix.  The expansion is performed before the
merging of multiple <code>xsl:output</code> elements into a single
effective <code>xsl:output</code> element. If the expanded-name of the
parent of a text node is a member of the list, then the text node
should be output as a CDATA section. For example,</p>

<eg><![CDATA[<xsl:output cdata-section-elements="example"/>]]></eg>

<p>would cause a literal result element written in the stylesheet as</p>

<eg><![CDATA[<example>&lt;foo></example>]]></eg>

<p>or as</p>

<eg>&lt;example>&lt;![CDATA[&lt;foo>]]&gt;&lt;/example></eg>

<p>to be output as</p>

examples/REC-xslt-19991116.xml  view on Meta::CPAN

<eg>&lt;example&gt;&lt;![CDATA[]]]]&gt;&lt;![CDATA[&gt;]]&gt;&lt;/example&gt;</eg>

<p>If the text node contains a character that is not representable in
the character encoding being used to output the result tree, then the
currently open CDATA section should be closed before the character,
the character should be output using a character reference or entity
reference, and a new CDATA section should be opened for any further
characters in the text node.</p>

<p>CDATA sections should not be used except for text nodes that the
<code>cdata-section-elements</code> attribute explicitly specifies
should be output using CDATA sections.</p>

<p>The <code>xml</code> output method should output an XML declaration
unless the <code>omit-xml-declaration</code> attribute has the value
<code>yes</code>. The XML declaration should include both version
information and an encoding declaration. If the
<code>standalone</code> attribute is specified, it should include a
standalone document declaration with the same value as the value as
the value of the <code>standalone</code> attribute.  Otherwise, it
should not include a standalone document declaration; this ensures

examples/REC-xslt-19991116.xml  view on Meta::CPAN


<!ELEMENT xsl:output EMPTY>
<!ATTLIST xsl:output
  method %qname; #IMPLIED
  version NMTOKEN #IMPLIED
  encoding CDATA #IMPLIED
  omit-xml-declaration (yes|no) #IMPLIED
  standalone (yes|no) #IMPLIED
  doctype-public CDATA #IMPLIED
  doctype-system CDATA #IMPLIED
  cdata-section-elements %qnames; #IMPLIED
  indent (yes|no) #IMPLIED
  media-type CDATA #IMPLIED
>

<!ELEMENT xsl:key EMPTY>
<!ATTLIST xsl:key
  name %qname; #REQUIRED
  match %pattern; #REQUIRED
  use %expr; #REQUIRED
>

examples/grammar.xml  view on Meta::CPAN

The target names "<code>XML</code>", "<code>xml</code>", and so on are
reserved for standardization in this or future versions of this
specification.
The 
XML <termref def='dt-notation'>Notation</termref> mechanism
may be used for
formal declaration of PI targets.
</p>
</div2>
 
<div2 id='sec-cdata-sect'>
<head>CDATA Sections</head>
 
<p><termdef id="dt-cdsection" term="CDATA Section"><term>CDATA sections</term>
may occur 
anywhere character data may occur; they are
used to escape blocks of text containing characters which would
otherwise be recognized as markup.  CDATA sections begin with the
string "<code>&lt;![CDATA[</code>" and end with the string
"<code>]]&gt;</code>":
<scrap lang="ebnf">

examples/grammar2.xml  view on Meta::CPAN

The target names "<code>XML</code>", "<code>xml</code>", and so on are
reserved for standardization in this or future versions of this
specification.
The 
XML <termref def='dt-notation'>Notation</termref> mechanism
may be used for
formal declaration of PI targets.
</p>
</div2>
 
<div2 id='sec-cdata-sect'>
<head>CDATA Sections</head>
 
<p><termdef id="dt-cdsection" term="CDATA Section"><term>CDATA sections</term>
may occur 
anywhere character data may occur; they are
used to escape blocks of text containing characters which would
otherwise be recognized as markup.  CDATA sections begin with the
string "<code>&lt;![CDATA[</code>" and end with the string
"<code>]]&gt;</code>":
<scrap lang="ebnf">

lib/XML/XSLT.pm  view on Meta::CPAN

#    * Started to properly implement omit-xml-declaration
#
#    Revision 1.17  2002/01/13 10:35:00  gellyfish
#    Updated pod
#
#    Revision 1.16  2002/01/09 09:17:40  gellyfish
#    * added test for <xsl:text>
#    * Stylesheet whitespace stripping as per spec and altered tests ...
#
#    Revision 1.15  2002/01/08 10:11:47  gellyfish
#    * First cut at cdata-section-element
#    * test for above
#
#    Revision 1.14  2001/12/24 16:00:19  gellyfish
#    * Version released to CPAN
#
#    Revision 1.13  2001/12/20 09:21:42  gellyfish
#    More refactoring
#
#    Revision 1.12  2001/12/19 21:06:31  gellyfish
#    * Some refactoring and style changes

lib/XML/XSLT.pm  view on Meta::CPAN

        my $doctype_public = $attribs->getNamedItem('doctype-public');
        my $doctype_system = $attribs->getNamedItem('doctype-system');

        my $dp = defined $doctype_public ? $doctype_public->getNodeValue : '';

        $self->doctype_public($dp);

        my $ds = defined $doctype_system ? $doctype_system->getNodeValue : '';
        $self->doctype_system($ds);

        # cdata-section-elements should only be used if the output type
        # is XML but as we are not checking that right now ...

        my $cdata_section = $attribs->getNamedItem('cdata-section-elements');

        if ( defined $cdata_section )
        {
            my $cdata_sections = [];
            @{$cdata_sections} = split /\s+/, $cdata_section->getNodeValue();
            $self->cdata_sections($cdata_sections);
        }
    }
    else
    {
        $self->debug("Default Output options being used");
    }
}

sub omit_xml_declaration
{

lib/XML/XSLT.pm  view on Meta::CPAN

        }
        else
        {
            $self->{OMIT_XML_DECL} = $omit_xml_declaration ? 1 : 0;
        }
    }

    return exists $self->{OMIT_XML_DECL} ? $self->{OMIT_XML_DECL} : 0;
}

sub cdata_sections
{
    my ( $self, $cdata_sections ) = @_;

    if ( defined $cdata_sections )
    {
        $self->{CDATA_SECTIONS} = $cdata_sections;
    }

    $self->{CDATA_SECTIONS} = [] unless exists $self->{CDATA_SECTIONS};

    return wantarray() ? @{ $self->{CDATA_SECTIONS} } : $self->{CDATA_SECTIONS};
}

sub is_cdata_section
{
    my ( $self, $element ) = @_;

    my %cdata_sections;

    my @cdata_temp = $self->cdata_sections();
    @cdata_sections{@cdata_temp} = (1) x @cdata_temp;

    my $tagname;

    if ( defined $element and ref($element) and ref($element) eq 'XML::DOM' )
    {
        $tagname = $element->getTagName();
    }
    else
    {
        $tagname = $element;
    }

    # Will need to do namespace checking on this really

    return exists $cdata_sections{$tagname} ? 1 : 0;
}

sub output_version
{
    my ( $self, $output_version ) = @_;

    if ( defined $output_version )
    {
        $self->{OUTPUT_VERSION} = $output_version;
    }

lib/XML/XSLT.pm  view on Meta::CPAN

                $current_xml_selection_path, $current_result_node, $variables,
                $oldvariables );
        }
    }
    else
    {
        $self->debug( $ns . " does not match " . $self->xsl_ns() );

        # not entirely sure if this right but the spec is a bit vague

        if ( $self->is_cdata_section($xsl_tag) )
        {
            $self->debug("This is a CDATA section element");
            $self->_add_cdata_section( $xsl_node, $current_xml_node,
                $current_xml_selection_path, $current_result_node, $variables,
                $oldvariables );
        }
        else
        {
            $self->debug("This is a literal element");
            $self->_check_attributes_and_recurse( $xsl_node, $current_xml_node,
                $current_xml_selection_path, $current_result_node, $variables,
                $oldvariables );
        }
    }

    $self->_outdent();
}

sub _add_cdata_section
{
    my ( $self, $xsl_node, $current_xml_node, $current_xml_selection_path,
        $current_result_node, $variables, $oldvariables )
      = @_;

    my $node = $self->xml_document()->createElement( $xsl_node->getTagName );

    my $cdata = '';

    foreach my $child_node ( $xsl_node->getChildNodes() )
    {
        if ( $child_node->can('asString') )
        {
            $cdata .= $child_node->asString();
        }
        else
        {
            $cdata .= $child_node->getNodeValue();
        }
    }

    $node->addCDATA($cdata);

    $current_result_node->appendChild($node);

}

sub _add_and_recurse
{
    my ( $self, $xsl_node, $current_xml_node, $current_xml_selection_path,
        $current_result_node, $variables, $oldvariables )
      = @_;

t/cdata_sect.t  view on Meta::CPAN

# Test that cdata-section elements work 
# $Id: cdata_sect.t,v 1.4 2002/01/14 09:40:23 gellyfish Exp $

use Test::More tests => 7;

use strict;
use vars qw($DEBUGGING);

$DEBUGGING = 0;

use_ok('XML::XSLT');

# First example

my $stylesheet =<<EOS;
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version='1.0'>

<xsl:output cdata-section-elements="example"/>

<xsl:template match="/">
<example>&lt;foo></example>
</xsl:template>
</xsl:stylesheet>
EOS

my $xml = '<doc />';

# this is not the same as that in the spec because of white space issues

t/cdata_sect.t  view on Meta::CPAN


$parser->dispose();

# The data example - test 'Literal result as stylesheet'

$stylesheet =<<'EOS';
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version='1.0'>

<xsl:output cdata-section-elements="example"/>

<xsl:template match="/">
<example><![CDATA[<foo>]]></example>
</xsl:template>
</xsl:stylesheet>
EOS

$expected =<<EOE;
<?xml version="1.0" encoding="UTF-8"?>
<example><![CDATA[<foo>]]></example>



( run in 0.532 second using v1.01-cache-2.11-cpan-454fe037f31 )