Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

XML::XSLT v 50_5 error with xsl variables

by misterperl (Pilgrim)
on Feb 07, 2018 at 21:10 UTC ( [id://1208650]=perlquestion: print w/replies, xml ) Need Help??

misterperl has asked for the wisdom of the Perl Monks concerning the following question:

I created some XSLT that works 100% with the XML, when I visit the XML in a browser. No warnings and everything looks great. But when I try to generate HTML using XML::XSLT (transform), it does the generation but many fields are blank. I ran it with warnings, and I saw several errors like these:
get-node-from-path: Don't know what to do with path /$name1 = $name2 get-node-from-path: Don't know what to do with path /$namei/cell
in the first example, it's not even a path, its an xsl:if (which works on the static page), like <xsl:if test="$name1 = $name2"> where these are defined by statements like <xsl:variable name="name" select="@name" /> I looked in CPAN and it said variables were at least in some fashion, supported. But I'm thinking perhaps I've just reached the usable limits of XML::XSLT ? The browser is already very particular about the XML and XSLT being perfect, and since it renders there, I think my XML and XSLT are not the issue. And it appears I'm already on the latest release of XML::XSLT ....

Replies are listed 'Best First'.
Re: XML::XSLT v 50_5 error with xsl variables
by roboticus (Chancellor) on Feb 07, 2018 at 22:03 UTC

    misterperl:

    You're not showing any XML or XLST, so there's no way to help other than to guess.

    My guess is that you're running into a quoting issue somewhere. $name looks quite like a perl variable, after all.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

      I showed the pertinent XML/XSLT - I program for a corporation and its all propriety so I can't really share the data. There is nothing to guess about really - this line
      <xsl:if test="$name1 = $name2">
      produces that error. It doesn't matter what it's embedded in- that line produces that error, anywhere. Yes, XSL variables DO look like Perl variables. I didn't invent the xsl var syntax, so I don't know what you mean by that comment.

      The question is really not about the particulars of the XSLT or XML. If there was a quote or any other syntax error, the browser wouldn't have rendered it. Unlike HTML, the XSL tags must be perfect, or the browser throws errors. As I said, the browser is very particular about things being pristine. No, the question is more about do I need to abandon XML::XSLT since I've apparently reached a practical limit of it's capability to support xsl 2.0. I'm planning to ask my Ruby coder down the hall if he has a Ruby method to render the HTML. I've never encountered something Perl wasn't up to doing, but it feels like this is the one....

Re: XML::XSLT v 50_5 error with xsl variables
by haukex (Archbishop) on Feb 10, 2018 at 11:12 UTC

    You didn't show any code, example input, or expected output. You did say "I program for a corporation and its all propriety", but that doesn't prevent you from constructing a simple SSCCE that reproduces the issue. I had to build one myself, and only did that because I happened to be curious. I was able to reproduce the issue you described with XML::XSLT. Note that the latest non-developer release is now about 14 years old and the developer release 0.50_5 is ~5 years old.

    I would recommend switching to XML::LibXML and XML::LibXSLT, where the variables seem to work as expected.

    use warnings; use strict; use XML::LibXSLT; use XML::LibXML; my $source = XML::LibXML->load_xml( string => <<'END_XML' ); <foo> <x one="Foo" two="Bar" /> <x one="Quz" two="Quz" /> </foo> END_XML my $style_doc = XML::LibXML->load_xml( string => <<'END_XSLT', no_cdata => 1 ); <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <bar> <xsl:for-each select="foo/x"> <xsl:variable name="name1" select="@one" /> <xsl:variable name="name2" select="@two" /> <xsl:if test="$name1 = $name2"> <y><xsl:value-of select="@one"/></y> </xsl:if> </xsl:for-each> </bar> </xsl:template> </xsl:stylesheet> END_XSLT my $xslt = XML::LibXSLT->new(); my $stylesheet = $xslt->parse_stylesheet($style_doc); my $results = $stylesheet->transform($source); print $stylesheet->output_as_bytes($results); __END__ <?xml version="1.0"?> <bar><y>Quz</y></bar>

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1208650]
Approved by beech
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-04-18 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found