2 Replies Latest reply: Nov 12, 2013 12:16 AM by Debanjan Banerjee RSS

    Understanding XSL

    Debanjan Banerjee

      My XML File is as follows:

       

       

      <Apple>

        <Mango>

           <MyInfo>

        </MyInfo>

        </Mango>

        <Grape>

          <OtherInfo>

          </OtherInfo>

        </Grape>

        <Grape>

          <OtherInfo>

          </OtherInfo>

        </Grape>

        <Grape>

          <OtherInfo>

          </OtherInfo>

        </Grape>

        <Grape>

          <OtherInfo>

          </OtherInfo>

        </Grape>

        <Grape>

          <OtherInfo>

          </OtherInfo>

        </Grape>

        <Grape>

          <OtherInfo>

          </OtherInfo>

        </Grape>

        <Grape>

          <OtherInfo>

          </OtherInfo>

        </Grape>

        <Grape>

          <OtherInfo>

          </OtherInfo>

        </Grape>

        <Grape>

          <OtherInfo>

          </OtherInfo>

        </Grape>

      </Apple>

       

      My XSL Was :

       

       

      <?xml version="1.0" encoding="ISO-8859-1"?>

      <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:foo="Something" >

       

       

      <xsl:output method="text"/>

      <xsl:template match="/">

       

       

       

       

       

       

        <xsl:for-each select="foo:Apple/foo:Grape">

        <xsl:value-of select="foo:OtherInfo"/>

        <xsl:text>&#10;</xsl:text>

        </xsl:for-each>

       

      Now I want to select MyInfo from Mango tag in the same line. Please suggest How can I do that. I have heard there are sibling , preeceding sibling etc concept in xsl,but unable to figure it out anyway.

        • 1. Re: Understanding XSL
          odie_63

          You mean like this?

           

          input XML :

          <Apple xmlns="Something">

            <Mango>

              <MyInfo>Header info</MyInfo>

            </Mango>

            <Grape>

              <OtherInfo>Grape1</OtherInfo>

            </Grape>

            <Grape>

              <OtherInfo>Grape2</OtherInfo>

            </Grape>

            <Grape>

              <OtherInfo>Grape3</OtherInfo>

            </Grape>

          </Apple>

           

          input XSL :

          <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:foo="Something" >

            <xsl:output method="text"/>

            <xsl:template match="/">

              <xsl:variable name="header" select="foo:Apple/foo:Mango/foo:MyInfo"/>

              <xsl:for-each select="foo:Apple/foo:Grape">

                <xsl:value-of select="$header"/>

                <xsl:text>;</xsl:text>

                <xsl:value-of select="foo:OtherInfo"/>

                <xsl:text>&#10;</xsl:text>

              </xsl:for-each>

            </xsl:template>

          </xsl:stylesheet>

           

          output :

          Header info;Grape1

          Header info;Grape2

          Header info;Grape3

          • 2. Re: Understanding XSL
            Debanjan Banerjee

            This works, Thanks for the help...!!