in reply to Re^2: xml::xslt xpath question
in thread xml::xslt xpath question

Simplified XML:

<?xml version="1.0" encoding="utf-8"?> <PLMXML xmlns="http://www.plmxml.org/Schemas/PLMXMLSchema"> <Form subType="Part Revision Master"> <UserData> <UserValue title="cage_code" value="98747"/> </UserData> </Form> </PLMXML>

You keep mentioning spaces, but I don't see why that would be a problem.

Did you try fixing the the missing "[" I mentioned? If the first snippet doesn't work with the missing "[ fixed, I suspect a namespace problem. I don't know how XSLT deals with namespaces, so I can't help you there.

Outside of XSLT, your XPath would be wrong since it references elements in the null namespace while they are in the http://www.plmxml.org/Schemas/PLMXMLSchema namespace.

Replies are listed 'Best First'.
Re^4: xml::xslt xpath question
by Anonymous Monk on Jul 06, 2009 at 20:15 UTC
    It seems to have a problem handling spaces because when I use the following xpath statement
    <xsl:value-of select="/PLMXML/Form[@subType='Part Revision + Master']/UserData/UserValue[@title='cage_code']/@value"/>
    I get the following error
    get-node-from-path: Don't know what to do with path [attribute::subTyp +e='Part Re vision Master']/UserData/UserValue[attribute::title='cage_code']/attri +bute::valu e !!!
    But if I use the following xpath statement I don't catch an error.
    <xsl:value-of select="/PLMXML/Form[@id='id24']/UserData/Us +erValue[@title='cage_code']/@value"/>
      And I found the bug:
      elsif ( $path =~ s/^\/(child\:\:|)(\*|[\w\.\:\-]+)\[(\S+?)\]// ) ^^^^
      Switching that line to following should do the trick:
      elsif ( $path =~ s/^\/(child\:\:|)(\*|[\w\.\:\-]+)\[(.+?)\]//s )

      Reported.

        I don't understand. Where should I apply this to fix my problem? Thanks for your help!
      I can replicate your problem:

      foo.pl:

      #!/usr/bin/perl use strict; use warnings; use XML::XSLT qw( ); use Object::Destroyer qw( ); my $xslt = Object::Destroyer->new( XML::XSLT->new('foo.xslt', warnings => 1), 'dispose', ); $xslt->transform('foo.xml'); print $xslt->toString;

      foo.xml:

      <?xml version="1.0" encoding="utf-8"?> <PLMXML xmlns="http://www.plmxml.org/Schemas/PLMXMLSchema"> <Form id="id24" subType="Part Revision Master"> <UserData> <UserValue title="cage_code" value="98747"/> </UserData> </Form> </PLMXML>

      foo.xslt:

      <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Tr +ansform"> <xsl:template match="/"> <xsl:value-of select="/PLMXML/Form[@subType='Part Revision Master']/Us +erData/UserValue[@title='cage_code']/@value"/> </xsl:template> </xsl:stylesheet>

      Also tried:

      Works: "/PLMXML/Form[@id='id24']/UserData/UserValue[@title='cag +e_code']/@value" Doesn't work: "/PLMXML/Form[@subType='Part Revision Master']" Doesn't work: "/PLMXML/Form[@subType=&quot;Part Revision Master&quot;] +/UserData/UserValue[@title='cage_code']/@value"

      (This should have been in your original post)