Here I have pasted a sample of XML that was tag names like 21A,50F,21D,22B
.
Normally if I need to fetch a particular tag, I can use logic below easily in XSLT:
<xsl:choose>
<xsl:when test="tag[name = '21A'] ">
<xsl:choose>
<xsl:when test="substring(tag[name = '21A']/value,1,1) = '/'">
<xsl:variable name="result" select="concat(translate(tag[name = '21A']/value,',',' '),' ')"/>
<xsl:value-of select="substring(substring-before(substring-after($result,' '),' '),1,11)"/>
</xsl:when>
<xsl:when test="substring(tag[name = '21A']/value,1,1) != '/'">
<xsl:value-of select="substring(tag[name = '21A']/value,1,11)"/>
</xsl:when>
</xsl:choose>
</xsl:when>
</xsl:choose>
but here I have a requirement as Sequence A
and Sequence B
.
- the tags which populated above
50F
come undersequence A
- the tags which populated below
50F
come undersequence B
since we need to fetch the tags based on using 50F
tag. Can any one please give a suggestion?
<local>
<message>
<block4>
<tag>
<name>21A</name>
<value>ALW1031</value>
</tag>
<tag>
<name>50F</name>
<value>TESTING CITI BANK EFT9</value>
</tag>
<tag>
<name>21D</name>
<value>OUR</value>
</tag>
<tag>
<name>22B</name>
<value>ipubby</value>
</tag>
</block4>
</message>
</local>
output required:
ALW1031,OUR
Previously if suppose they have populate 21A
two times means I have used the position as [1] and [2] as while calling tag values. Now they will populate 21 tag repeatedly but tags may be A
or D
so I need to target 50f
tag blindly. Whatever tag they will provide, either A
or D
before 50F
I need to fetch similarly whatever they populate tags after 50F
we able to fetch so avoiding positions.
Summary:
@Treemonkey: hope you had a glance of my sample XML. It has some tag like 21A,50F
and so on. Assume if I have two fields field1,field2
earlier they have populated tags as same repeated tags as 21A
at that time I have fetched as 21A
having beside by marking position [1] for field 1 (tag[name = '21A'][1]
)
Similarly 21A
having beside by marking position [2] for field 2, now they will populate 21
but tags were different as A
or D
. As I have said field1
should concentrate sequence A
and field2
should concentrate as sequence B
so now we should not bother about positions for fetch we have a demarcation like tag 50F
whatever fields will populate before 50F
has to treated as sequence A
and after 50F
has to be treated as sequence B
.
So finally we need to write as XSLT by targeting 50
F. If I want to display 21A
field in (sample XML) which before 50F
so we need write a logic in XSLT as select tag 21A
before 50F
tag for to produce data in field 1 and for field 2 we need to fetch as 21D
after 50F
so we need to write a logic as select 21D
after 50F
.