on 09-08-2010 7:09 AM
Hi ,
my source structure is
<?xml version="1.0" encoding="UTF-8"?>
<records>
<field1>a</field1>
<field2>b</field2>
<field3>c</field3>
<field4>d</field4>
..........................
..............................
,,,,,,,,,,,,,,
</records>
my output should be
<?xml version="1.0" encoding="UTF-8"?>
<output>
<record>
<data>field1</data>
<value>a</value>
<counter>1/<counter>
</record>
<record>
<data>field2</data>
<value>b</value>
<counter>2/<counter>
</record>
<record>
<data>field3</data>
<value>c</value>
<counter>3/<counter>
</record>
<record>
<data>field4</data>
<value>d</value>
<counter>4/<counter>
</record>
........................
.............................
..................
</output>
basically i need the syntax for...
1) looping each element and then passing the corresponding tag name and value
2) increament.
thnx
The following should do the trick:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/records">
<output>
<xsl:for-each select="*">
<record>
<data><xsl:value-of select="local-name(.)"/></data>
<value><xsl:value-of select="."/></value>
</record>
</xsl:for-each>
</output>
</xsl:template>
</xsl:stylesheet>
Cheers, harald
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
This is the sample code,to loop
<xsl:template match="/*">
<xsl:for-each select="record">
<data>value fo select filed 1(u need to select the first position value)</data>
<value><xsl:text>a</xsl:text></QUALF>
</xsl:for-each>
</xsl:template>
Regards,
Raj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I think we need to use the java mapping or you can go with the simple graphical mapping by replicating the target structure and hard coding the fields names that come from source side.
Regards,
Sainath Chutke
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Sam,
Probably what you can do is:
Take a count of the tags for the number of times your target structure has to repeat.
Then create a different template for for loop.
Inside this ue " <xsl:if test="$i <= $count"> " where $i is the begin of the loop and $Count if the max number for the loop to repeat.
Now you can use foreach tag of xslt to generate the target structure desired.
Code for ur ref:
<xsl:template name="for.loop">
<xsl:param name="i" />
<xsl:param name="count"/>
<xsl:if test="$i <= $count">
<item>
<xsl:for-each select="The X-Path">
<xsl:variable name="XYZ">
<xsl:value-of select="ABC" />
</xsl:variable>
</xsl:for-each>
</item>
</xsl:template>
Suggestion: Enough info is available if you google with "using for loop in XSL"
Hope this hels.
Warm Regards,
Anshul
Edited by: Anshul Chowdhary on Sep 8, 2010 9:26 AM
User | Count |
---|---|
81 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.