www.webdeveloper.com
Results 1 to 7 of 7

Thread: Expecting the following output using XSLT

  1. #1
    Join Date
    Mar 2008
    Posts
    7

    Expecting the following output using XSLT

    Hi friends,

    i have one XML input , and with the help of XSLT i have to bring the expected output.

    here is my XML input:

    <A>
    <B>
    <a1>123</a1>
    <a2>456</a2>
    </B>
    </A>



    using XSLT i have to bring the following output:

    A.B.a1=123
    A.B.a2=456


    My question is what is to be written in XSLT so that i could bring the above output. i kindly request anyone to reply to this request as soon as possible

  2. #2
    Join Date
    Mar 2008
    Location
    Bordeaux, France
    Posts
    57
    Code:
     <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:output method="text"/>
    	<xsl:template match="/">
    		<xsl:for-each select="//*[text()]">
    			<xsl:for-each select="ancestor::*">
    				<xsl:value-of select="concat(name(),'.')"/>
    			</xsl:for-each>
    			<xsl:value-of select="concat(name(),'=',text())"/>
    			<xsl:text>
    </xsl:text>
    		</xsl:for-each>
    	</xsl:template>
     </xsl:stylesheet>
    I first tried with <xsl:sort select="position()" order="descending"/> in the ancestor loop because it is a reverse axis but .Net does not like it...

  3. #3
    Join Date
    Mar 2008
    Posts
    7

    thanks

    thanks alian.the code which u gave is really helpful.

  4. #4
    Join Date
    Mar 2008
    Posts
    7

    need explanation

    can u please explain me why you gave <xsl:for-each select="ancestor::*"> in that code

  5. #5
    Join Date
    Mar 2008
    Location
    Bordeaux, France
    Posts
    57
    The first xsl:for-each is to locate elements with text and only them : there will be one output line for each.

    The second xsl:for-each has to find each ancestor of this kind of elements : ancestor::* means all ancestors from the current element being elements themselves (ancestors are always elements but this syntax is also used for siblings for example). The names of these ancestors have not to be known to retrieve them and the function name() can then be used to get each ancestor name.

    I tried to give you the most versatile transformation considering the depth and the element names might not be constant.

  6. #6
    Join Date
    Apr 2008
    Posts
    4
    Hi Alain:
    i have one XML input , and with the help of XSLT i have to bring the expected output.

    here is my XML input:
    <Attributes Protected="false" AddNewP="false" ReOrderP="false">
    <ProtectedItem Protected="true">
    <Value Name="FA1" DataType="Value" Filter="String">
    <string>sdfg</string>
    </Value>
    </ProtectedItem>
    <ProtectedItem Protected="true">
    <Value Name="FA12" DataType="FileLink" Filter="*">
    <string>D:\TimeSheet\2008\AVLIS_Timesheet_TFMS_VikramSingh_CW_13.xls</string>
    </Value>
    </ProtectedItem>
    <ProtectedItem Protected="false">
    <Value Name="FA13" DataType="WebLink" Filter="*">
    <string>http://localhost:1799/CfgWS</string>
    </Value>
    </ProtectedItem>
    <ProtectedItem Protected="true">
    <Value Name="FA14" DataType="Attachment" Filter="*.*">
    <ReferenceObjectPaco Name="corpora.txt" Date="2007-08-02T10:15:39.65625+05:30" Size="699" FilePath="C:\Documents and Settings\SINGHV\Desktop\Jan Kachra\corpora.txt" Modified="true" Zipped="true" ReferenceType="Attachment" DataType="Attachment">
    <User />
    <Reference Type="Attachment" Name="f7cf713e-dd90-4f5c-a9a1-637084e7385a" PacoRefName="Ref:FA[FA14]" />
    <ReferenceValue xmlns:q8="http://www.w3.org/2001/XMLSchema" p7:type="q8:string" xmlns7="http://www.w3.org/2001/XMLSchema-instance">corpora.txt</ReferenceValue>
    </ReferenceObjectPaco>
    </Value>
    </ProtectedItem>
    <ProtectedItem Protected="false">
    <Value Name="FA15" DataType="Standard" Filter="*.*">
    <ReferenceObjectPaco Name="FA15" Date="2008-04-01T14:02:03.6875+05:30" UserName="System" Size="80384" FilePath="C:\Documents and Settings\leinera\Desktop\TFMS Training\TFMS-Glossary V1_1.xls" Modified="false" Zipped="false" ReferenceType="Standard" DataType="Standard" Filter="*.*">
    <User />
    <Reference Type="Standard" SubType="xls" Name="Glossary" PacoRefName="Ref:FA[FA15]" />
    <ReferenceValue xmlns:q9="http://www.w3.org/2001/XMLSchema" p7:type="q9:string" xmlns7="http://www.w3.org/2001/XMLSchema-instance">Glossary</ReferenceValue>
    </ReferenceObjectPaco>
    </Value>
    </ProtectedItem>
    <ProtectedItem Protected="true">
    <Value Name="FA16" DataType="Value" Filter="Integer">
    <string>234</string>
    </Value>
    </ProtectedItem>
    </Attributes>

    using XSLT i have to bring the following output:

    <FreeAttribute Name="FA1" DataType="Value" Filter="String" Value="sdfg" />
    <FreeAttribute Name="FA12" DataType="FileLink" Filter="*" Value="D:\TimeSheet\2008\AVLIS_Timesheet_TFMS_VikramSingh_CW_13.xls" />
    <FreeAttribute Name="FA13" DataType="WebLink" Filter="*" Value="http://localhost:1799/CfgWS" />
    <FreeAttribute Name="FA14" DataType="Attachment" Filter="*.*" Value="" />
    <FreeAttribute Name="FA15" DataType="Standard" Filter="*.*" Value="" />
    <FreeAttribute Name="FA16" DataType="Value" Filter="Integer" Value="234" />

    My question is what is to be written in XSLT so that i could bring the above output. i kindly request anyone to reply to this request as soon as possible

  7. #7
    Join Date
    Mar 2008
    Location
    Bordeaux, France
    Posts
    57
    Try this stylesheet :
    Code:
    <xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:template match="/">
    		<Attributes>
    			<xsl:for-each select="/Attributes/ProtectedItem">
    				<FreeAttribute Name="{Value/@Name}" DataType="{Value/@Name}" Filter="{Value/@Name}" Value="{Value/string}"/>
    			</xsl:for-each>
    		</Attributes>
    	</xsl:template>
    </xsl:stylesheet>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles