Hi,

I have an XML file generated via PHP, and containing the contents of several 
linked tables from a relational database. I would like to generalize some 
sample XSLT documents to convert the entire file into a sequence of CSV 
files. The XML file will essentially be exploded back into a set of CSV 
files, one for each of the original tables. The idea would be to create a 
couple XSLT files for converting the XML format into several possible output 
formats. 

Attached is the XML file, as well as two XSLT files. I suppose that I could 
loop over the tables of interest, and apply separate XSLT files to the 
original XML-- saving to different output files each time. It would be more 
convenient to have all of that logic embedded in the XSLT file-- if possible.

Any ideas?

Cheers,
Dylan


-- 
Dylan Beaudette
Soil Resource Laboratory
http://casoilresource.lawr.ucdavis.edu/
University of California at Davis
530.754.7341
<?xml version="1.0"?>
<pedon_collection>
  <pedon>
    <description>
      <creation_date>2008-08-02 22:13:15</creation_date>
      <modification_date>2009-08-17 12:30:17</modification_date>
      <pedon_id>S08CALATIGO-001</pedon_id>
      <transect_bearing></transect_bearing>
      <transect_stop></transect_stop>
      <transect_interval></transect_interval>
      <date>2008-05-30</date>
      <time>10:00:00</time>
      <describers>DB,ATO</describers>
      <air_temp_c>23</air_temp_c>
      <soil_temp_c></soil_temp_c>
      <soil_temp_depth></soil_temp_depth>
      <topo_quad></topo_quad>
      <landscape>FH</landscape>
      <landform>HI</landform>
      <microrelief>ML</microrelief>
      <field_elevation></field_elevation>
      <field_aspect>200</field_aspect>
      <field_slope_pct></field_slope_pct>
      <slope_complexity>S</slope_complexity>
      <slope_shape_down></slope_shape_down>
      <slope_shape_across></slope_shape_across>
      <hill_profile_position>BS</hill_profile_position>
      <geomorphic_component>SS</geomorphic_component>
      <type></type>
      <drainage>MW</drainage>
      <flooding>NO</flooding>
      <ponding>NO</ponding>
      <soil_moisture_status>M</soil_moisture_status>
      <permeability></permeability>
      <land_cover>SNS</land_cover>
      <parent_material>SAL/SAP</parent_material>
      <bedrock_kind>GRE</bedrock_kind>
      <bedrock_fracture_class>5</bedrock_fracture_class>
      <bedrock_depth>60</bedrock_depth>
      <lithostratic_units>Calaveras Formation</lithostratic_units>
      <erosion_kind></erosion_kind>
      <erosion_degree></erosion_degree>
      <surface_frags_gr></surface_frags_gr>
      <surface_frags_cb></surface_frags_cb>
      <surface_frags_st></surface_frags_st>
      <surface_frags_bd></surface_frags_bd>
      <surface_frags_cn></surface_frags_cn>
      <surface_frags_fl></surface_frags_fl>
      <pcs_dep_top>12</pcs_dep_top>
      <pcs_dep_bottom>60</pcs_dep_bottom>
      <field_classification>Fine, mixed, semiactive, thermic, Mollic Haploxeralf</field_classification>
      <project_id>1</project_id>
    </description>
    <pedon_spatial>
      <pedon_id>S08CALATIGO-001</pedon_id>
      <x>-120.68351190131</x>
      <y>38.0963938542273</y>
      <precision_meters>1</precision_meters>
    </pedon_spatial>
    <diagnostic>
      <diagnostic_record>
        <pedon_id>S08CALATIGO-001</pedon_id>
        <diagnostic_index>0</diagnostic_index>
        <kind>Ochric</kind>
        <top>0</top>
        <bottom>12</bottom>
      </diagnostic_record>
      <diagnostic_record>
        <pedon_id>S08CALATIGO-001</pedon_id>
        <diagnostic_index>1</diagnostic_index>
        <kind>Argillic</kind>
        <top>12</top>
        <bottom>60</bottom>
      </diagnostic_record>
      <diagnostic_record>
        <pedon_id>S08CALATIGO-001</pedon_id>
        <diagnostic_index>2</diagnostic_index>
        <kind>Paralithic</kind>
        <top>60</top>
        <bottom></bottom>
      </diagnostic_record>
    </diagnostic>
    <vegetation>
      <vegetation_record>
        <pedon_id>S08CALATIGO-001</pedon_id>
        <veg_index>1</veg_index>
        <common_name>blue oak</common_name>
        <pct_cover>20</pct_cover>
        <usda_code>QUDO</usda_code>
      </vegetation_record>
      <vegetation_record>
        <pedon_id>S08CALATIGO-001</pedon_id>
        <veg_index>2</veg_index>
        <common_name>live oak</common_name>
        <pct_cover>20</pct_cover>
        <usda_code>QUAG</usda_code>
      </vegetation_record>
      <vegetation_record>
        <pedon_id>S08CALATIGO-001</pedon_id>
        <veg_index>3</veg_index>
        <common_name>ann. grasses</common_name>
        <pct_cover>20</pct_cover>
        <usda_code></usda_code>
      </vegetation_record>
    </vegetation>
    <notes>
      <notes_record>
        <pedon_id>S08CALATIGO-001</pedon_id>
        <note_index>1</note_index>
        <note>pasture #2 at Latigo</note>
      </notes_record>
      <notes_record>
        <pedon_id>S08CALATIGO-001</pedon_id>
        <note_index>2</note_index>
        <note>nearby outcropping of greenstone</note>
      </notes_record>
      <notes_record>
        <pedon_id>S08CALATIGO-001</pedon_id>
        <note_index>3</note_index>
        <note>under oak canopy</note>
      </notes_record>
      <notes_record>
        <pedon_id>S08CALATIGO-001</pedon_id>
        <note_index>4</note_index>
        <note>metasediment outcroppings at summit</note>
      </notes_record>
    </notes>
    <memo>
      <memo_record>
        <pedon_id>S08CALATIGO-001</pedon_id>
        <memo>texture class derived from lab data.</memo>
      </memo_record>
    </memo>
    <horizon>
      <horizon_record>
        <pedon_id>S08CALATIGO-001</pedon_id>
        <hz_number>2</hz_number>
        <observation_method>SP</observation_method>
        <top>3</top>
        <bottom>12</bottom>
        <name>Ad</name>
        <bound_distinct>A</bound_distinct>
        <bound_topography>W</bound_topography>
        <matrix_dry_color_hue>5YR</matrix_dry_color_hue>
        <matrix_dry_color_value>5.0</matrix_dry_color_value>
        <matrix_dry_color_chroma>6.0</matrix_dry_color_chroma>
        <matrix_wet_color_hue>5YR</matrix_wet_color_hue>
        <matrix_wet_color_value>3.0</matrix_wet_color_value>
        <matrix_wet_color_chroma>4.0</matrix_wet_color_chroma>
        <texture>LCOS</texture>
        <structure_grade_1></structure_grade_1>
        <structure_size_1></structure_size_1>
        <structure_type_1>MA</structure_type_1>
        <parts_to_flag></parts_to_flag>
        <structure_grade_2></structure_grade_2>
        <structure_size_2></structure_size_2>
        <structure_type_2></structure_type_2>
        <dry_consistance>SH</dry_consistance>
        <moist_consistance></moist_consistance>
        <stickiness>SS</stickiness>
        <plasticity>SP</plasticity>
        <field_ph></field_ph>
        <field_reaction_hcl></field_reaction_hcl>
        <field_pct_clay>20</field_pct_clay>
        <notes>hoof-pan. Mn masses present</notes>
      </horizon_record>
      <horizon_record>
        <pedon_id>S08CALATIGO-001</pedon_id>
        <hz_number>1</hz_number>
        <observation_method>SP</observation_method>
        <top>0</top>
        <bottom>3</bottom>
        <name>A</name>
        <bound_distinct>A</bound_distinct>
        <bound_topography>S</bound_topography>
        <matrix_dry_color_hue>7.5YR</matrix_dry_color_hue>
        <matrix_dry_color_value>4.0</matrix_dry_color_value>
        <matrix_dry_color_chroma>4.0</matrix_dry_color_chroma>
        <matrix_wet_color_hue>7.5YR</matrix_wet_color_hue>
        <matrix_wet_color_value>3.0</matrix_wet_color_value>
        <matrix_wet_color_chroma>3.0</matrix_wet_color_chroma>
        <texture>LCOS</texture>
        <structure_grade_1>1</structure_grade_1>
        <structure_size_1>VF</structure_size_1>
        <structure_type_1>SBK</structure_type_1>
        <parts_to_flag></parts_to_flag>
        <structure_grade_2>1</structure_grade_2>
        <structure_size_2>F</structure_size_2>
        <structure_type_2>SBK</structure_type_2>
        <dry_consistance>VH</dry_consistance>
        <moist_consistance></moist_consistance>
        <stickiness>SO</stickiness>
        <plasticity>PO</plasticity>
        <field_ph></field_ph>
        <field_reaction_hcl></field_reaction_hcl>
        <field_pct_clay>12</field_pct_clay>
        <notes>hydrophobic</notes>
      </horizon_record>
      <horizon_record>
        <pedon_id>S08CALATIGO-001</pedon_id>
        <hz_number>3</hz_number>
        <observation_method>SP</observation_method>
        <top>12</top>
        <bottom>26</bottom>
        <name>Bt1</name>
        <bound_distinct>A</bound_distinct>
        <bound_topography>W</bound_topography>
        <matrix_dry_color_hue>5YR</matrix_dry_color_hue>
        <matrix_dry_color_value>5.0</matrix_dry_color_value>
        <matrix_dry_color_chroma>6.0</matrix_dry_color_chroma>
        <matrix_wet_color_hue>2.5YR</matrix_wet_color_hue>
        <matrix_wet_color_value>4.0</matrix_wet_color_value>
        <matrix_wet_color_chroma>6.0</matrix_wet_color_chroma>
        <texture>CBVL</texture>
        <structure_grade_1>1</structure_grade_1>
        <structure_size_1>CO</structure_size_1>
        <structure_type_1>SBK</structure_type_1>
        <parts_to_flag></parts_to_flag>
        <structure_grade_2>1</structure_grade_2>
        <structure_size_2>M</structure_size_2>
        <structure_type_2>SBK</structure_type_2>
        <dry_consistance></dry_consistance>
        <moist_consistance>FI</moist_consistance>
        <stickiness>SS</stickiness>
        <plasticity>SP</plasticity>
        <field_ph></field_ph>
        <field_reaction_hcl></field_reaction_hcl>
        <field_pct_clay>24</field_pct_clay>
        <notes>very porous matrix</notes>
      </horizon_record>
      <horizon_record>
        <pedon_id>S08CALATIGO-001</pedon_id>
        <hz_number>4</hz_number>
        <observation_method>SP</observation_method>
        <top>26</top>
        <bottom>60</bottom>
        <name>Bt2</name>
        <bound_distinct>A</bound_distinct>
        <bound_topography>W</bound_topography>
        <matrix_dry_color_hue></matrix_dry_color_hue>
        <matrix_dry_color_value></matrix_dry_color_value>
        <matrix_dry_color_chroma></matrix_dry_color_chroma>
        <matrix_wet_color_hue>2.5YR</matrix_wet_color_hue>
        <matrix_wet_color_value>3.0</matrix_wet_color_value>
        <matrix_wet_color_chroma>6.0</matrix_wet_color_chroma>
        <texture>CL</texture>
        <structure_grade_1>2</structure_grade_1>
        <structure_size_1>M</structure_size_1>
        <structure_type_1>SBK</structure_type_1>
        <parts_to_flag></parts_to_flag>
        <structure_grade_2></structure_grade_2>
        <structure_size_2></structure_size_2>
        <structure_type_2></structure_type_2>
        <dry_consistance></dry_consistance>
        <moist_consistance></moist_consistance>
        <stickiness>MS</stickiness>
        <plasticity>VP</plasticity>
        <field_ph></field_ph>
        <field_reaction_hcl></field_reaction_hcl>
        <field_pct_clay>30</field_pct_clay>
        <notes>too moist for a dry color</notes>
      </horizon_record>
      <horizon_record>
        <pedon_id>S08CALATIGO-001</pedon_id>
        <hz_number>5</hz_number>
        <observation_method>SP</observation_method>
        <top>60</top>
        <bottom>60</bottom>
        <name>Crt</name>
        <bound_distinct></bound_distinct>
        <bound_topography></bound_topography>
        <matrix_dry_color_hue></matrix_dry_color_hue>
        <matrix_dry_color_value></matrix_dry_color_value>
        <matrix_dry_color_chroma></matrix_dry_color_chroma>
        <matrix_wet_color_hue></matrix_wet_color_hue>
        <matrix_wet_color_value></matrix_wet_color_value>
        <matrix_wet_color_chroma></matrix_wet_color_chroma>
        <texture></texture>
        <structure_grade_1></structure_grade_1>
        <structure_size_1></structure_size_1>
        <structure_type_1></structure_type_1>
        <parts_to_flag></parts_to_flag>
        <structure_grade_2></structure_grade_2>
        <structure_size_2></structure_size_2>
        <structure_type_2></structure_type_2>
        <dry_consistance></dry_consistance>
        <moist_consistance></moist_consistance>
        <stickiness></stickiness>
        <plasticity></plasticity>
        <field_ph></field_ph>
        <field_reaction_hcl></field_reaction_hcl>
        <field_pct_clay></field_pct_clay>
        <notes>paralithic meta-volcanic. variegated colors</notes>
      </horizon_record>
    </horizon>
    <hz_frags>
      <hz_frags_record>
        <pedon_id>S08CALATIGO-001</pedon_id>
        <hz_number>2</hz_number>
        <fragkind>GR</fragkind>
        <fragvol>10</fragvol>
        <frags_key>144</frags_key>
      </hz_frags_record>
      <hz_frags_record>
        <pedon_id>S08CALATIGO-001</pedon_id>
        <hz_number>1</hz_number>
        <fragkind>GR</fragkind>
        <fragvol>8</fragvol>
        <frags_key>429</frags_key>
      </hz_frags_record>
      <hz_frags_record>
        <pedon_id>S08CALATIGO-001</pedon_id>
        <hz_number>3</hz_number>
        <fragkind>CB</fragkind>
        <fragvol>50</fragvol>
        <frags_key>700</frags_key>
      </hz_frags_record>
      <hz_frags_record>
        <pedon_id>S08CALATIGO-001</pedon_id>
        <hz_number>4</hz_number>
        <fragkind>GR</fragkind>
        <fragvol>13</fragvol>
        <frags_key>834</frags_key>
      </hz_frags_record>
    </hz_frags>
    <hz_roots>
      <hz_roots_record>
        <pedon_id>S08CALATIGO-001</pedon_id>
        <hz_number>2</hz_number>
        <rootsquantity>3</rootsquantity>
        <rootssize>M</rootssize>
        <rootslocation>T</rootslocation>
        <rootstemp_raw_data></rootstemp_raw_data>
        <c_flag></c_flag>
        <roots_key>1460</roots_key>
      </hz_roots_record>
      <hz_roots_record>
        <pedon_id>S08CALATIGO-001</pedon_id>
        <hz_number>4</hz_number>
        <rootsquantity>3</rootsquantity>
        <rootssize>M</rootssize>
        <rootslocation>T</rootslocation>
        <rootstemp_raw_data></rootstemp_raw_data>
        <c_flag></c_flag>
        <roots_key>1467</roots_key>
      </hz_roots_record>
      <hz_roots_record>
        <pedon_id>S08CALATIGO-001</pedon_id>
        <hz_number>4</hz_number>
        <rootsquantity>3</rootsquantity>
        <rootssize>F</rootssize>
        <rootslocation>T</rootslocation>
        <rootstemp_raw_data></rootstemp_raw_data>
        <c_flag></c_flag>
        <roots_key>1468</roots_key>
      </hz_roots_record>
      <hz_roots_record>
        <pedon_id>S08CALATIGO-001</pedon_id>
        <hz_number>3</hz_number>
        <rootsquantity>5</rootsquantity>
        <rootssize>F</rootssize>
        <rootslocation>T</rootslocation>
        <rootstemp_raw_data></rootstemp_raw_data>
        <c_flag></c_flag>
        <roots_key>1474</roots_key>
      </hz_roots_record>
      <hz_roots_record>
        <pedon_id>S08CALATIGO-001</pedon_id>
        <hz_number>3</hz_number>
        <rootsquantity>3</rootsquantity>
        <rootssize>M</rootssize>
        <rootslocation>T</rootslocation>
        <rootstemp_raw_data></rootstemp_raw_data>
        <c_flag></c_flag>
        <roots_key>1475</roots_key>
      </hz_roots_record>
      <hz_roots_record>
        <pedon_id>S08CALATIGO-001</pedon_id>
        <hz_number>1</hz_number>
        <rootsquantity>3</rootsquantity>
        <rootssize>VF</rootssize>
        <rootslocation>T</rootslocation>
        <rootstemp_raw_data></rootstemp_raw_data>
        <c_flag></c_flag>
        <roots_key>1539</roots_key>
      </hz_roots_record>
      <hz_roots_record>
        <pedon_id>S08CALATIGO-001</pedon_id>
        <hz_number>1</hz_number>
        <rootsquantity>3</rootsquantity>
        <rootssize>F</rootssize>
        <rootslocation>T</rootslocation>
        <rootstemp_raw_data></rootstemp_raw_data>
        <c_flag></c_flag>
        <roots_key>1540</roots_key>
      </hz_roots_record>
    </hz_roots>
    <hz_pores/>
    <hz_mottles/>
    <hz_pvsf>
      <hz_pvsf_record>
        <pedon_id>S08CALATIGO-001</pedon_id>
        <hz_number>3</hz_number>
        <pvsfpct>15</pvsfpct>
        <pvsfdistinct></pvsfdistinct>
        <pvsfcont></pvsfcont>
        <pvsfkind>CLF</pvsfkind>
        <pvsflocation>PF</pvsflocation>
        <pvsfcolor></pvsfcolor>
        <pvsftemp_raw_data></pvsftemp_raw_data>
        <pvsf_key>83</pvsf_key>
      </hz_pvsf_record>
      <hz_pvsf_record>
        <pedon_id>S08CALATIGO-001</pedon_id>
        <hz_number>4</hz_number>
        <pvsfpct>90</pvsfpct>
        <pvsfdistinct></pvsfdistinct>
        <pvsfcont></pvsfcont>
        <pvsfkind>CLF</pvsfkind>
        <pvsflocation>PF</pvsflocation>
        <pvsfcolor></pvsfcolor>
        <pvsftemp_raw_data></pvsftemp_raw_data>
        <pvsf_key>84</pvsf_key>
      </hz_pvsf_record>
      <hz_pvsf_record>
        <pedon_id>S08CALATIGO-001</pedon_id>
        <hz_number>5</hz_number>
        <pvsfpct></pvsfpct>
        <pvsfdistinct></pvsfdistinct>
        <pvsfcont></pvsfcont>
        <pvsfkind>CLF</pvsfkind>
        <pvsflocation></pvsflocation>
        <pvsfcolor></pvsfcolor>
        <pvsftemp_raw_data></pvsftemp_raw_data>
        <pvsf_key>85</pvsf_key>
      </hz_pvsf_record>
    </hz_pvsf>
    <hz_rmf>
      <hz_rmf_record>
        <pedon_id>S08CALATIGO-001</pedon_id>
        <hz_number>2</hz_number>
        <rdxfeatkind>MNM</rdxfeatkind>
        <rdxfeatpct>2</rdxfeatpct>
        <rdxfeatsize>1</rdxfeatsize>
        <rdxfeatcntrst>P</rdxfeatcntrst>
        <rdxfeatcolor></rdxfeatcolor>
        <rdxfeatshape></rdxfeatshape>
        <rdxfeatlocation>MAT</rdxfeatlocation>
        <rdxfeatboundary></rdxfeatboundary>
        <rmf_key>11</rmf_key>
      </hz_rmf_record>
      <hz_rmf_record>
        <pedon_id>S08CALATIGO-001</pedon_id>
        <hz_number>2</hz_number>
        <rdxfeatkind>MNM</rdxfeatkind>
        <rdxfeatpct>2</rdxfeatpct>
        <rdxfeatsize>2</rdxfeatsize>
        <rdxfeatcntrst>P</rdxfeatcntrst>
        <rdxfeatcolor></rdxfeatcolor>
        <rdxfeatshape></rdxfeatshape>
        <rdxfeatlocation>MAT</rdxfeatlocation>
        <rdxfeatboundary></rdxfeatboundary>
        <rmf_key>12</rmf_key>
      </hz_rmf_record>
    </hz_rmf>
  </pedon>
</pedon_collection>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output method="text" encoding="iso-8859-1"/>

  <xsl:param name="delim" select="string(',')" />
  <xsl:param name="quote" select="string('&quot;')" />
  <xsl:param name="break" select="string('&#xD;')" />

  <xsl:template match="/">
    <xsl:apply-templates select="pedon_collection/pedon/description" />
  </xsl:template>

  <xsl:template match="description">
    <xsl:apply-templates />
    <xsl:if test="following-sibling::*">
      <xsl:value-of select="$break" />
    </xsl:if>
  </xsl:template>

  <xsl:template match="*">
    <!-- remove normalize-space() if you want keep white-space at it is --> 
    <xsl:value-of select="concat($quote, normalize-space(.), $quote)" />
    <xsl:if test="following-sibling::*">
      <xsl:value-of select="$delim" />
    </xsl:if>
  </xsl:template>
  
  <xsl:template match="text()" />
</xsl:stylesheet>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output method="text" encoding="iso-8859-1"/>

  <xsl:param name="delim" select="string(',')" />
  <xsl:param name="quote" select="string('&quot;')" />
  <xsl:param name="break" select="string('&#10;')" />

  <xsl:template match="/">
    <xsl:apply-templates select="pedon_collection/pedon/horizon/horizon_record" />
  </xsl:template>

  <xsl:template match="horizon_record">
    <xsl:apply-templates />
    <xsl:if test="following-sibling::*">
      <xsl:value-of select="$break" />
    </xsl:if>
  </xsl:template>

  <xsl:template match="*">
    <!-- remove normalize-space() if you want keep white-space at it is --> 
    <xsl:value-of select="concat($quote, normalize-space(.), $quote)" />
    <xsl:if test="following-sibling::*">
      <xsl:value-of select="$delim" />
    </xsl:if>
  </xsl:template>
  
  <xsl:template match="text()" />
</xsl:stylesheet>
_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech

Reply via email to