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

I'll add the full xml below but my biggest challenge is in finding the xpath methods that are available in Perl to select a node by its attributute value - when the attribute value includes space.

<?xml version="1.0" encoding="utf-8" ?> - <PLMXML xmlns="http://www.plmxml.org/Schemas/PLMXMLSchema" schemaVer +sion="5.1" date="2009-06-23" time="10:44:53" author="TcEng"> <Header id="id1" traverseRootRefs="#id6 #id52 #id2 #id15 #id30 #id33 + #id19" transferContext="AFexportEO" /> - <ProductRevision id="id15" name="160D999998-98" accessRefs="#id3" su +bType="EngChange Revision" masterRef="#id17" revision="A"> <Description>this is the change description defined upon change crea +tion</Description> <ApplicationRef version="BSApEoC5hbVAiA" application="TcEng" label=" +BOGpEoC5hbVAiA" /> - <UserData id="id16"> <UserValue value="2009-06-23T10:42:59" title="creation_date" /> </UserData> <AssociatedForm id="id32" role="IMAN_specification" formRef="#id30" +/> <AssociatedForm id="id35" role="IMAN_specification" formRef="#id33" +/> <AssociatedForm id="id38" role="IMAN_master_form_rev" formRef="#id36 +" /> </ProductRevision> - <ProductRevision id="id19" name="new part" accessRefs="#id3" subType +="Part Revision" masterRef="#id21" revision="01"> <ApplicationRef version="xlIpEoC5hbVAiA" application="TcEng" label=" +xdEpEoC5hbVAiA" /> - <UserData id="id20"> <UserValue value="2009-06-23T10:41:19" title="creation_date" /> </UserData> <AssociatedForm id="id29" role="IMAN_master_form_rev" formRef="#id24 +" /> </ProductRevision> - <Product id="id21" name="new part" accessRefs="#id3" subType="Part" +productId="160D999998-98"> <ApplicationRef version="xdEpEoC5hbVAiA" application="TcEng" label=" +xdEpEoC5hbVAiA" /> - <UserData id="id22"> <UserValue value="2009-06-23T10:41:19" title="creation_date" /> </UserData> </Product> - <WorkflowProcess id="id2" name="09A10-000019/A-160D999998-98" ownerR +ef="#id6" templateName="AF Eng Order - TSW Val - test"> <ApplicationRef version="heLpEoC5hbVAiA" application="TcEng" label=" +heLpEoC5hbVAiA" /> <Task id="id14" name="AF Eng Order - TSW Val - test" state="started" + subTaskRefs="#id40 #id44 #id47 #id50 #id60 #id63" targetRefs="#id15 +#id30 #id33 #id19" /> <Task id="id40" name="IPT Lead - Initiate Eng Order" state="complete +d" subTaskRefs="#id41 #id43" /> - <Task id="id41" name="select-signoff-team" state="completed"> - <Signoff id="id42" decision="Approved" decisionDate="2009-06-23T10:4 +4:29" organisationMemberRef="#id6"> <ApplicationRef version="xCHpEoC5hbVAiA" application="TcEng" label=" +xCHpEoC5hbVAiA" /> </Signoff> </Task> <Task id="id43" name="perform-signoffs" state="completed" /> <Task id="id44" name="Material Science Lab Approval" state="pending" + subTaskRefs="#id45 #id46" /> <Task id="id45" name="select-signoff-team" state="pending" /> <Task id="id46" name="perform-signoffs" state="pending" /> <Task id="id47" name="Configuration Mgt 2nd Approval" state="pending +" subTaskRefs="#id48 #id49" /> <Task id="id48" name="select-signoff-team" state="pending" /> <Task id="id49" name="perform-signoffs" state="pending" /> <Task id="id50" name="Equipment Specialist Approval" state="started" + subTaskRefs="#id51 #id59" /> - <Task id="id51" name="select-signoff-team" state="completed"> - <Signoff id="id58" decision="Approved" decisionDate="2009-06-23T10:4 +4:53" organisationMemberRef="#id52"> <ApplicationRef version="h_HpEoC5hbVAiA" application="TcEng" label=" +h_HpEoC5hbVAiA" /> </Signoff> </Task> <Task id="id59" name="perform-signoffs" state="completed" /> <Task id="id60" name="Drafting Office Approval" state="pending" subT +askRefs="#id61 #id62" /> <Task id="id61" name="select-signoff-team" state="pending" /> <Task id="id62" name="perform-signoffs" state="pending" /> <Task id="id63" name="Configuration Mgt Approval" state="pending" su +bTaskRefs="#id64 #id65" /> <Task id="id64" name="select-signoff-team" state="pending" /> <Task id="id65" name="perform-signoffs" state="pending" /> </WorkflowProcess> <AccessIntent id="id3" intent="reference" ownerRefs="#id4" /> - <Site id="id4" name="HAFB-A10" siteId="509939746"> - <UserData id="id5"> <UserValue value="HAFB-A10-DEV" title="connect_string" /> <UserValue value="1" title="dbms" /> </UserData> </Site> <OrganisationMember id="id6" roleRef="#id13" organisationRef="#id11" + memberRef="#id7" /> - <User id="id7" personRef="#id8" userId="craig.poulson"> - <UserData id="id10"> <UserValue value="craig.poulson" title="os_username" /> <UserValue value="0" title="status" /> <UserValue type="reference" value="" title="default_group" dataRef=" +#id11" /> </UserData> </User> - <Person id="id8" lastName="craig.poulson"> - <UserData id="id9"> <UserValue value="6057 Box Elder Lane Bldg 1285" title="PA1" /> <UserValue value="Hill AFB" title="PA2" /> <UserValue value="UT" title="PA3" /> <UserValue value="84056-5811" title="PA4" /> <UserValue value="USA" title="PA5" /> <UserValue value="538 ACSG" title="PA6" /> <UserValue value="" title="PA7" /> <UserValue value="CDPMailCode" title="PA8" /> <UserValue value="craig.poulson.ctr@hill.af.mil" title="PA9" /> <UserValue value="(801) 586-0054" title="PA10" /> </UserData> </Person> - <Organisation id="id11" name="AF_ADMIN"> - <UserData id="id12"> <UserValue type="reference" value="" title="list_of_role" dataRef="# +id13" /> <UserValue type="int" value="1" title="privilege" /> </UserData> </Organisation> - <Role id="id13" name="DBA"> <Description>Database Administrator.</Description> </Role> - <Change id="id17" name="160D999998-98" ownerRef="#id11" changeId="09 +A10-000019"> <Description>this is the change description defined upon change crea +tion</Description> <ApplicationRef version="BOGpEoC5hbVAiA" application="TcEng" label=" +BOGpEoC5hbVAiA" /> - <UserData id="id18"> <UserValue value="2009-06-23T10:42:59" title="creation_date" /> </UserData> </Change> - <GeneralRelation id="id23" subType="EC_affected_item_rel" relatedRef +s="#id15 #id19"> <ApplicationRef version="BmLpEoC5hbVAiA" application="TcEng" label=" +BmLpEoC5hbVAiA" /> </GeneralRelation> - <Form id="id24" name="160D999998-98/01" accessRefs="#id3" subType="P +art Revision Master" subClass="Part Revision Master"> <ApplicationRef version="xVOpEoC5hbVAiA" application="TcEng" label=" +xVOpEoC5hbVAiA" /> - <UserData id="id28" type="FormAttributes"> <UserValue value="0-01-00T00:00:00" title="Eff_Update_Date" /> <UserValue type="reference" value="" title="Eff_Update_User" /> <UserValue value="" title="aircraft_location" /> <UserValue value="" title="aircraft_system" /> <UserValue value="NX5" title="cad_version" /> <UserValue value="98747" title="cage_code" /> <UserValue type="real" value="" title="comp_length" /> <UserValue value="" title="complexity_code" /> <UserValue value="" title="criticality_code" /> <UserValue value="" title="definition_format" /> <UserValue value="D: DoD and Contractors (controlling DoD office)" t +itle="dist_statement" /> <UserValue value="OO-ALC/508 ACSS/SU, Hill AFB, UT, 84056" title="do +d_office" /> <UserValue value="YES" title="export_control" /> - <UserValue value="" title="fab_process"> <UserList id="id25" type="list" /> </UserValue> <UserValue value="" title="field_1" /> <UserValue value="" title="field_2" /> <UserValue value="" title="i_and_r_code" /> <UserValue value="" title="make_from_part_no" /> <UserValue value="" title="material_desc" /> - <UserValue value="" title="material_desc_a"> <UserList id="id26" type="list" /> </UserValue> <UserValue value="" title="material_spec" /> - <UserValue value="" title="material_spec_a"> <UserList id="id27" type="list" /> </UserValue> <UserValue type="real" value="" title="max_raw_stock_thickness" /> <UserValue value="" title="mirror_or_opp" /> <UserValue value="" title="mirror_or_opp_part_no" /> <UserValue value="A10WRP-07-0021" title="modeling_spec" /> <UserValue type="real" value="" title="part_length" /> <UserValue type="real" value="" title="part_thickness" /> <UserValue value="" title="part_type" /> <UserValue type="real" value="" title="part_width" /> <UserValue value="tbd" title="procurement_code" /> <UserValue value="" title="procurement_spec" /> <UserValue value="DOD Controlled" title="proprietary" /> <UserValue value="Unclassified" title="security" /> <UserValue value="" title="size_code" /> <UserValue value="NX" title="system_master" /> <UserValue type="boolean" value="" title="traceable" /> <UserValue value="" title="traceable_s" /> <UserValue value="" title="traceable_type" /> <UserValue type="boolean" value="" title="uid_value" /> <UserValue value="" title="uid_value_s" /> <UserValue value="" title="vendor_name" /> <UserValue value="" title="wbs" /> <UserValue value="" title="wbs_definition" /> <UserValue value="" title="wbs_definition_mfg" /> <UserValue value="" title="weight_updated" /> <UserValue value="0-01-00T00:00:00" title="weight_updated_date" /> <UserValue value="FA8202-07-C-0004-P00001 (ESM)" title="work_authori +ty" /> </UserData> </Form> - <Form id="id30" name="09A10-000019/A-AF Engineering Or" accessRefs=" +#id3" subType="AF Engineering Order E" subClass="AF Engineering Order + E"> <ApplicationRef version="BGIpEoC5hbVAiA" application="TcEng" label=" +BGIpEoC5hbVAiA" /> - <UserData id="id31" type="FormAttributes"> <UserValue value="Unclassified" title="af_eo_destruction" /> <UserValue value="D" title="af_eo_distribution" /> <UserValue value="Y" title="af_eo_warnings" /> <UserValue value="98747" title="af_eoopr_cagecode" /> <UserValue value="" title="af_eoreason_des_chg" /> <UserValue value="X" title="af_eoreason_dwg_cla" /> <UserValue value="X" title="af_eoreason_err_cor" /> <UserValue value="this is the other reason for change" title="af_eor +eason_other" /> <UserValue value="X" title="af_eoreason_upd_dwg" /> <UserValue value="Modify" title="af_eospares_disposition" /> <UserValue value="other info about spares disposition" title="af_eos +pares_disposition_oth" /> <UserValue value="Change Notice" title="af_eotype" /> <UserValue value="i can't think of any other comments" title="af_oth +er_comments" /> <UserValue value="A-10" title="af_used_on" /> </UserData> </Form> - <Form id="id33" name="09A10-000019/A-AF Design/Draftin" accessRefs=" +#id3" subType="AF Design/Drafting Request A" subClass="AF Design/Draf +ting Request A"> <ApplicationRef version="BGOpEoC5hbVAiA" application="TcEng" label=" +BGOpEoC5hbVAiA" /> - <UserData id="id34" type="FormAttributes"> <UserValue value="0-01-00T00:00:00" title="af_dddesired_date" /> <UserValue value="" title="af_dddistro" /> <UserValue value="" title="af_ddnewdata" /> <UserValue value="" title="af_ddproofrq" /> <UserValue value="" title="af_ddrevdata" /> <UserValue value="" title="af_ddweapon_sys" /> <UserValue value="" title="af_ddworkdesc" /> </UserData> </Form> - <Form id="id36" name="09A10-000019/A" accessRefs="#id3" subType="Eng +Change Revision Master" subClass="EngChange Revision Master"> <ApplicationRef version="BSDpEoC5hbVAiA" application="TcEng" label=" +BSDpEoC5hbVAiA" /> - <UserData id="id37" type="FormAttributes"> <UserValue value="AF Engineering Order B" title="ec_type" /> </UserData> </Form> - <ReleaseStatus id="id39" name="Validated" dateReleased="0-01-00T00:0 +0:00"> <ApplicationRef version="xSEpEoC5hbVAiA" application="TcEng" label=" +xSEpEoC5hbVAiA" /> </ReleaseStatus> <OrganisationMember id="id52" roleRef="#id57" organisationRef="#id53 +" memberRef="#id7" /> - <Organisation id="id53" name="AF Equipment Specialist.AF Equipment S +upport.AF TSW.AF A10"> - <UserData id="id54"> <UserValue type="reference" value="" title="list_of_role" dataRef="# +id55" /> <UserValue type="reference" value="" title="list_of_role" dataRef="# +id56" /> <UserValue type="reference" value="" title="list_of_role" dataRef="# +id57" /> <UserValue type="int" value="0" title="privilege" /> </UserData> </Organisation> <Role id="id55" name="AF Admin" /> <Role id="id56" name="AF Analyst" /> <Role id="id57" name="AF Designer" /> </PLMXML>

Replies are listed 'Best First'.
Re^3: xml::xslt xpath question
by ikegami (Patriarch) on Jul 06, 2009 at 20:00 UTC

    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.

      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 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)