0 Replies Latest reply on Mar 25, 2014 5:10 PM by fruitsalad

    Use XML Node Value as Node name and as attribute name

    fruitsalad Level 1

      im quite new to XML and XLST. I got an Open Office XML file that I transformed with XLST.

       

       

      <?xml version="1.0" encoding="UTF-8"?>
      <ooo_calc_export scriptVersion="2.2.0" scriptUpdate="2010-12-19" scriptURL="http://www.digitalimprint.com/misc/oooexport/" scriptAuthor="vjl">
         <ooo_sheet num="1" name="Blatt1">
            <ooo_row><Artikelnummer>C12-34567</Artikelnummer><ArttikelnummerAlt/><Details>AAA AAA AAA AAA</Details><Abmessungen/><Bildpfad>file:///cmyk/C12-34567.PSD</Bildpfad><EK>1234,-</EK><VK>3456,-</VK>
              </ooo_row>
            <ooo_row><Artikelnummer>C23-45678</Artikelnummer><ArttikelnummerAlt/><Details>BaB BaB BBB BBB</Details><Abmessungen/><Bildpfad>file:///cmyk/cmyk/C23-45678.PSD</Bildpfad><EK>2345,-</EK><VK>4567,-</VK>
              </ooo_row>
            <ooo_row><Artikelnummer>C34-56789</Artikelnummer><ArttikelnummerAlt/><Details>CaC CaC CaC CaC uli</Details><Abmessungen/><Bildpfad>file:///cmyk/cmyk/C34-56789.PSD</Bildpfad><EK>3456,-</EK><VK>5678,-</VK>
              </ooo_row>
         </ooo_sheet>
      </ooo_calc_export>

       

       

      I transformed the XML with the following XLST:

       

       

      <?xml version="1.0" encoding="UTF-8"?>
      <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
        <xsl:output method = "xml" version="1.0" encoding="UTF-8" indent="yes"/>
        <xsl:strip-space elements="*"/>
        <xsl:template match="ooo_sheet">
      <xsl:element name="Import">
      <xsl:for-each select="ooo_row">
      <xsl:element name="Artikel">
        <xsl:element name="Text">
              <xsl:copy-of select="Artikelnummer"/> 
              <xsl:copy-of select="Details"/> 
              <xsl:copy-of select="Abmessungen"/> 
              <xsl:copy-of select="EK"/>
        </xsl:element>
      
      </xsl:element>
      </xsl:for-each>
      </xsl:element>
      </xsl:template>

       

       

      The result is:

       

       

      <?xml version="1.0" encoding="UTF-8"?>
      <Import>
          <Artikel>
              <Text>
                  <Artikelnummer>C12-34567</Artikelnummer>
                  <Details>AAA AAA AAA AAA</Details>
                  <Abmessungen/>
                  <EK>1234,-</EK>
              </Text>
          </Artikel>
          <Artikel>
              <Text>
                  <Artikelnummer>C23-45678</Artikelnummer>
                  <Details>BaB BaB BBB BBB</Details>
                  <Abmessungen/>
                  <EK>2345,-</EK>
              </Text>
          </Artikel>
          <Artikel>
              <Text>
                  <Artikelnummer>C34-56789</Artikelnummer>
                  <Details>CaC CaC CaC CaC uli</Details>
                  <Abmessungen/>
                  <EK>3456,-</EK>
              </Text>
          </Artikel>
      </Import>

       

       

      I need another child within the node "Artikel" named "Bild". It should have an "href" attribute. The value of the attribute should be the value in the node "Bildpfad".

      The result of this transformation should be

       

      ...
      <Artikel>
        <Text>
          <Artikelnummer>C34-56789</Artikelnummer>
          <Details>CaC CaC CaC CaC uli</Details>
          <Abmessungen/>
          <EK>3456,-</EK>
        </Text>
        <Bild href="file:///cmyk/C12-34567.PSD"></Bild>
      </Artikel>
      ...
      

       

       

      I want to import this XML into Indesign. It seems that the images path needs to be in a href attribute so Indesign accepts the node as an image object.

       

      Another problem is that Indesign won't import the original xml with selection of the listed xsl to tranform the xml. So I used another xml editor instead to perform the transformation.

       

      Thank you all for your help!