filemaker - XPath to parse eCFR XML using attributes and nodes -
this question has been edited make things bit clearer.
i attempting pull data out of electronic code of federal regulations xml feed (http://www.gpo.gov/fdsys/bulkdata/cfr/2015/title-15/cfr-2015-title15-vol2.xml) , having trouble.
specifically, i'd grab data matched combination of node , attribute. in following snippet of xml, can see of text i'd grab. obtain data each fp node attribute fp-2 present. grab data each fp node having attribute fp-1.
<appendix> <ear>pt. 774, supp. 1</ear> <hd source="hed">supplement no. 1 part 774—the commerce control list</hd> <hd source="hd1">category 0—nuclear materials, facilities, , equipment [and miscellaneous items]</hd> <hd source="hd1">a. “end items,” “equipment,” “accessories,” “attachments,” “parts,” “components,” , “systems”</hd> <fp source="fp-2"> <e t="02">0a002power generating or propulsion equipment “specially designed” use space, marine or mobile “nuclear reactors”. (these items “subject itar.” see 22 cfr parts 120 through 130.)</e> </fp> <fp source="fp-2"> <e t="02">0a018items on wassenaar munitions list (see list of items controlled).</e> </fp> <fp source="fp-1"> <e t="04">license requirements</e> </fp> <fp source="fp-1"> <e t="03">reason control:</e> ns, at, un</fp> <gpotable cdef="s50,r50" cols="2" opts="l2"> <boxhd> <ched h="1">control(s)</ched> <ched h="1">country chart (see supp. no. 1 part 738)</ched> </boxhd> <row> <ent i="01">ns applies entire entry</ent> <ent>ns column 1.</ent> </row> <row> <ent i="01">at applies entire entry</ent> <ent>at column 1.</ent> </row> <row> <ent i="01">un applies entire entry</ent> <ent>see § 746.1(b) un controls.</ent> </row> </gpotable> <fp source="fp-1"> <e t="05">list based license exceptions (see part 740 description of license exceptions)</e> </fp> <fp source="fp-1"> <e t="03">lvs:</e> $3,000 0a018.b</fp> <fp source="fp-1">$1,500 0a018.c , .d</fp> <fp source="fp-1"> <e t="03">gbs:</e> n/a</fp> <fp source="fp-1"> <e t="03">civ:</e> n/a</fp> <fp source="fp-1"> <e t="04">list of items controlled</e> </fp> <fp source="fp-1"> <e t="03">related controls:</e> (1) see 0a979, 0a988, , 22 cfr 121.1 categories i(a), iii(b-d), , x(a). (2) see eccn 0a617.y.1 , .y.2 items formerly controlled eccn 0a018.a. (3) see eccn 1a613.c military helmets providing less nij type iv protection , eccn 1a613.y.1 conventional military steel helmets that, prior july 1, 2014, classified under 0a018.d , 0a988. (4) see 22 cfr 121.1 category x(a)(5) , (a)(6) controls on other military helmets.</fp> <fp source="fp-1"> <e t="03">related definitions:</e> n/a</fp> <fp> <e t="03">items:</e> a. [reserved]</fp> <p>b. “specially designed” components , parts ammunition, except cartridge cases, powder bags, bullets, jackets, cores, shells, projectiles, boosters, fuses , components, primers, , other detonating devices , ammunition belting , linking machines (all of “subject itar.” (see 22 cfr parts 120 through 130);</p> <note> <hd source="hed"> <e t="03">note:</e> </hd> <p> <e t="03">0a018.b not apply “components” “specially designed” blank or dummy ammunition follows:</e> </p> <p> <e t="03">a. ammunition crimped without projectile (blank star);</e> </p> </appendix>
to complicate matters, i'm trying pull data filemaker, upon edit, i'll stick simple xsl.
the following xsl grabs of fp nodes without differentiation.
<?xml version='1.0' encoding='utf-8'?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:template match="/"> <xsl:for-each select="//fp"> <xsl:value-of select="."/> </xsl:for-each> </xsl:template> </xsl:stylesheet>
modifying match on xsl:template match="fp[@source='fp-1'] allows me make necessary match based on attribute, i'm still not clear on how capture data need. thoughts?
a few things:
- your xslt not xslt format
- in xpath, reference attribute (i.e., source), must prefixed
@
. - finally, there many fp1s , fp2s setup choose first instances.
consider following xslt:
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0"> <xsl:output version="1.0" encoding="utf-8"/> <xsl:template match="/"> <fmpxmlresult xmlns="http://www.filemaker.com/fmpxmlresult"> <metadata> <field name="eccnfp_2" type="text"/> <field name="eccnfp_1" type="text"/> </metadata> <resultset> <xsl:for-each select="//fp[@source = 'fp-2']/e[@t='02']"> <row> <col> <data><xsl:value-of select="substring(.,1,5)"/></data> </col> </row> </xsl:for-each> <xsl:for-each select="//fp[@source = 'fp-1']/e[@t='02']"> <row> <col> <data><xsl:value-of select="substring(.,1,5)"/></data> </col> </row> </xsl:for-each> </resultset> </fmpxmlresult> </xsl:template> </xsl:stylesheet>
which output:
<?xml version='1.0' encoding='utf-8'?> <fmpxmlresult xmlns="http://www.filemaker.com/fmpxmlresult"> <metadata> <field name="eccnfp_2" type="text"/> <field name="eccnfp_1" type="text"/> </metadata> <resultset> <row> <col> <data>0a002</data> </col> </row> <row> <col> <data>0a018</data> </col> </row> </resultset> </fmpxmlresult>
and partial output of full web link xml:
<?xml version='1.0' encoding='utf-8'?> <fmpxmlresult xmlns="http://www.filemaker.com/fmpxmlresult"> <metadata> <field name="eccnfp_2" type="text"/> <field name="eccnfp_1" type="text"/> </metadata> <resultset> <row> <col> <data>2a000</data> </col> </row> <row> <col> <data>0a002</data> </col> </row> <row> <col> <data>0a018</data> </col> </row> <row> <col> <data>0a521</data> </col> </row> <row> <col> <data>0a604</data> </col> </row> <row> <col> <data>0a606</data> </col> </row> ...
in fact, point xslt processor gpo link , fp1s , fp2s output. did python! close 3,000 lines!
Comments
Post a Comment