3 Replies Latest reply on Oct 27, 2014 12:12 PM by MW Design

    How do I change alphabetical element listing in xml to nested xml using xslt?

    PM2049

      Have an 'Bus Card Request' indd form exported to fillable form pdf (reader enabled etc). Have 'Bus Card Template' indd to receive the BC data from the returned filled pdf form.

       

      The tags & structure are identical on both indd docs.

       

      The xml exported from the pdf discards the structure (nesting) and provides all the elements in alphabetical order.

       

      I am a novice learning how to make an xslt that will transform the alphabetical listing back to the nested structure.

       

      I want to turn this:

      <?xml version="1.0" encoding="UTF-8"?>

      <fields xmlns:xfdf="http://ns.adobe.com/xfdf-transition/">

      <Address>1234 Take Wing</Address>

      <Cell_Number>619.321.6878</Cell_Number>

      <City>San Diego</City>

      <Clin_Sup_Lic_Number>SL00267</Clin_Sup_Lic_Number>

      <Clinical_Supervisor_Name>Jarmal Hincks</Clinical_Supervisor_Name>

      <ComboBox2 xfdf:original="Combo Box 2">sdyouthservices.org</ComboBox2>

      <Date_Signed_Loc_Dir>9/29/2014a</Date_Signed_Loc_Dir>

      <Date_Signed_Orig>9/29/2014</Date_Signed_Orig>

      <Degree>MA</Degree>

      <Email_Address>s.reeves</Email_Address>

      <Extension>1234</Extension>

      <Fax_Number>619.123.9876</Fax_Number>

      <Intern_Number>XX20</Intern_Number>

      <License_Number>YY20</License_Number>

      <Location>Point Loma Campus</Location>

      <Name>Steve Reeves</Name>

      <Notes_and_Comments>Make it a super duper bus card</Notes_and_Comments>

      <Program>Learning Curve</Program>

      <State>CA</State>

      <Telephone_Number>619.123.4567</Telephone_Number>

      <TextField27 xfdf:original="Text Field 27">www.sdyouthservices.org</TextField27>

      <Title>Superman</Title>

      <Zip>99999</Zip>

      </fields>

       

      into this:

       

      <BC_Order>

      <Group_Name>

         <Name></Name>

         <Degree></Degree>

         
<Title></Title>

         <Intern_Number></Intern_Number>

         <License_Number></License_Number>

      </Group_Name>

       

      <Group_Location>

         <Location></Location>

        
<Program></Program>

        
<Address></Address>


        <City></City>

        <State></State>

        <Zip></Zip>

      </Group_Location>

       

      <Group_Phone>

        <Telephone_Number></Telephone_Number>

        <Extension></Extension>


        <Fax_Number></Fax_Number>

        <Cell_Number></Cell_Number>

      </Group_Phone>

       

      <Group_Email-WS>

        <Email_Address></Email_Address>

        <eMail_Host></eMail_Host>


        <Website></Website>


        <Clinical_Supervisor_Name></Clinical_Supervisor_Name>

        <Clin_Sup_Lic_Number></Clin_Sup_Lic_Number>

      </Group_Email-WS>

       

      </BC_Order>

      ____________________________

       

      Is this xslt code on the right track?

      (i've left out the usual header stuff)

       

      <BC_Order>

      <Group_Name>

      <Name><xsl:value-of select="Name"/></Name>

      <Degree><xsl:value-of select="Degree"/></Degree>

      <Title><xsl:value-of select="Title"/></Title>

      <Intern_Number><xsl:value-of select="Intern_Number"/></Intern_Number>

      <License_Number><xsl:value-of select="License_Number"/></License_Number>

      </Group_Name>

       

      </BC_Order>

       

      I'm just trying to figure out what the words are to make nesting occur in the resultant xml so it will match the nesting order in the Bus Card input template.

       

      Thanks!

      Paul

        • 1. Re: How do I change alphabetical element listing in xml to nested xml using xslt?
          MW Design Level 4

          Hi Paul,

          Is this xslt code on the right track?

          Yes, no...


          The root element in the XML from the form is "fields" without the quote marks. So the XSL needs the full path to the elements to include the "fields" root element. The select would therefore be "<xsl:value-of select="fields/Name" />"


          Note that because I like seeing the XML with line breaks, the "<xsl:text>&#xA;</xsl:text>" precedes each line. Without that, one gets a long string. But it isn't really needed and there are other means of accomplishing it.


          I think the below will do what you need.


          Take care, Mike


          <?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:text>&#xA;</xsl:text><BC_Order>

          <xsl:text>&#xA;</xsl:text><Group_Name>

          <xsl:text>&#xA;</xsl:text><Name><xsl:value-of select="fields/Name" /></Name>

          <xsl:text>&#xA;</xsl:text><Degree><xsl:value-of select="fields/Degree" /></Degree>

          <xsl:text>&#xA;</xsl:text><Title><xsl:value-of select="fields/Title" /></Title>

          <xsl:text>&#xA;</xsl:text><Intern_Number><xsl:value-of select="fields/Intern_Number" /></Intern_Number>

          <xsl:text>&#xA;</xsl:text><License_Number><xsl:value-of select="fields/License_Number" /></License_Number>

          <xsl:text>&#xA;</xsl:text></Group_Name>

          <xsl:text>&#xA;</xsl:text><Group_Location>

          <xsl:text>&#xA;</xsl:text><Location><xsl:value-of select="fields/Location" /></Location>

          <xsl:text>&#xA;</xsl:text><Program><xsl:value-of select="fields/Program" /></Program>

          <xsl:text>&#xA;</xsl:text><Address><xsl:value-of select="fields/Address" /></Address>

          <xsl:text>&#xA;</xsl:text><City><xsl:value-of select="fields/City" /></City>

          <xsl:text>&#xA;</xsl:text><State><xsl:value-of select="fields/State" /></State>

          <xsl:text>&#xA;</xsl:text><Zip><xsl:value-of select="fields/Zip" /></Zip>

          <xsl:text>&#xA;</xsl:text></Group_Location>

          <xsl:text>&#xA;</xsl:text><Group_Phone>

          <xsl:text>&#xA;</xsl:text><Telephone_Number><xsl:value-of select="fields/Telephone_Number" /></Telephone_Number>

          <xsl:text>&#xA;</xsl:text><Extension><xsl:value-of select="fields/Extension" /></Extension>

          <xsl:text>&#xA;</xsl:text><Fax_Number><xsl:value-of select="fields/Fax_Number" /></Fax_Number>

          <xsl:text>&#xA;</xsl:text><Cell_Number><xsl:value-of select="fields/Cell_Number" /></Cell_Number>

          <xsl:text>&#xA;</xsl:text></Group_Phone>

          <xsl:text>&#xA;</xsl:text><Group_Email-WS>

          <xsl:text>&#xA;</xsl:text><Email_Address><xsl:value-of select="fields/Email_Address" /></Email_Address>

          <xsl:text>&#xA;</xsl:text><eMail_Host><xsl:value-of select="fields/ComboBox2" /></eMail_Host>

          <xsl:text>&#xA;</xsl:text><Website><xsl:value-of select="fields/TextField27" /></Website>

          <xsl:text>&#xA;</xsl:text><Clinical_Supervisor_Name><xsl:value-of select="fields/Clinical_Supervisor_Name" /></Clinical_Supervisor_Name>

          <xsl:text>&#xA;</xsl:text><Clin_Sup_Lic_Number><xsl:value-of select="fields/Clin_Sup_Lic_Number" /></Clin_Sup_Lic_Number>

          <xsl:text>&#xA;</xsl:text></Group_Email-WS>

          <xsl:text>&#xA;</xsl:text></BC_Order>

          </xsl:template>

          </xsl:stylesheet>

          • 2. Re: How do I change alphabetical element listing in xml to nested xml using xslt?
            PM2049 Level 1

            Thanks Mike, this worked.   I've been trying to snake this thing out for three months.

            • 3. Re: How do I change alphabetical element listing in xml to nested xml using xslt?
              MW Design Level 4

              You are most welcome. Glad it worked for you.

               

              Mike