Skip Menu |

This queue is for tickets about the XML-XSLT CPAN distribution.

Report information
The Basics
Id: 18482
Status: resolved
Priority: 0/
Queue: XML-XSLT

People
Owner: Nobody in particular
Requestors: jdhedden [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.48
Fixed in: (no value)



Subject: Support for <xsl:value-of select="elem[@attr='value']"/>
The attached patch adds support for: <xsl:value-of select="elem[@attr='value']"/> <xsl:value-of select="//elem[@attr='value']"/> This patch builds on the 'indent' patch previously submitted for http://rt.cpan.org/Ticket/Display.html?id=18476 This patch may partially resolve problems reported in http://rt.cpan.org/Ticket/Display.html?id=16312
Subject: elem_by_attr.patch
--- XSLT.pm.indent 2006-03-31 09:20:12.000000000 -0500 +++ XSLT.pm.elem 2006-03-31 11:29:16.000000000 -0500 @@ -2731,6 +2731,13 @@ return &__attribute__( $self, $1, $path, $node, $silent ); } + elsif ($path =~ s/^\/descendant\-or\-self\:\:node\(\)\/(child\:\:|)(\*|[\w\.\:\-]+)\[\s*attribute\:\:(\S+?)\s*=[\s'"]*(\S+?)[\s'"]*\]//) + { + # //elem[@attr=value] # + $self->debug(qq{Getting deep element '$2' with attribute '$3' equal to '$4' ("$path")}); + $self->_outdent(); + return &__element_by_attribute__( $self, $2, $3, $4, $path, $node, $silent, "deep" ); + } elsif ( $path =~ s/^\/descendant\-or\-self\:\:node\(\)\/(child\:\:|)(\*|[\w\.\:\-]+)\[(\S+?)\]// ) @@ -2752,6 +2759,13 @@ return &__element__( $self, $1, $path, $node, $silent, "deep" ); } + elsif ($path =~ s/^\/(child\:\:|)(\*|[\w\.\:\-]+)\[\s*attribute\:\:(\S+?)\s*=[\s'"]*(\S+?)[\s'"]*\]//) + { + # /elem[@attr=value] # + $self->debug(qq{Getting element '$2' with attribute '$3' equal to '$4' ("$path")}); + $self->_outdent(); + return &__element_by_attribute__( $self, $2, $3, $4, $path, $node, $silent ); + } elsif ( $path =~ s/^\/(child\:\:|)(\*|[\w\.\:\-]+)\[(\S+?)\]// ) { @@ -2876,6 +2890,30 @@ return $node; } +sub __element_by_attribute__ +{ + my ( $self, $element, $attr, $value, $path, $node, $silent, $deep ) = @_; + $deep ||= ""; # False # + + my @list; + foreach my $elem ($node->getElementsByTagName($element, $deep)) { + if ($elem->getAttribute($attr) eq $value) { + push(@list, $elem); + } + } + + $self->_indent(); + if (@list) { + $node = &__get_node_set__($self, $path, \@list, $silent); + } else { + $self->debug("Failed"); + $node = []; + } + $self->_outdent(); + + return $node; +} + sub __element__ { my ( $self, $element, $path, $node, $silent, $deep ) = @_; @@ -3947,6 +3985,10 @@ <xsl:value-of select="//elem"/> +<xsl:value-of select="elem[@attr='value']"/> + +<xsl:value-of select="//elem[@attr='value']"/> + <xsl:value-of select="elem[n]"/> <xsl:value-of select="//elem[n]"/>
On Fri Mar 31 11:33:52 2006, JDHEDDEN wrote: Show quoted text
> The attached patch adds support for: > <xsl:value-of select="elem[@attr='value']"/> > <xsl:value-of select="//elem[@attr='value']"/> > > This patch builds on the 'indent' patch previously submitted for > http://rt.cpan.org/Ticket/Display.html?id=18476 > > This patch may partially resolve problems reported in > http://rt.cpan.org/Ticket/Display.html?id=16312
Hi, I've implemented this in a different way in https://github.com/jonathanstowe/XML-XSLT/commit/2127a5e2cb93c1e0b4dffb1a7ef7a00ed89c2fd9 Thanks.