简体   繁体   中英

How to Read Java List Object in XSL

I am having a Java Object which is ArrayList and i have added it in response of service which is in XML format as below,

<root>
<SubRoot>
<type>A</type>
<mand>Y</mand>
<Section>B</Section>
</SubRoot>
<SubRoot>
<type>A</type>
<mand>Y</mand>
<Section>A</Section>
</SubRoot>
</root>

I am trying to use the some value from above xml for condition.On basis of true condition i will call some template for my purpose.

I am calling my xsl template as below,

<xsl:choose>
       <xsl:when test="(/root/SubRoot[Section = 'A'])">
    //Call some template 
    </xsl:when>
    <xsl:otherwise>
    //some template
</xsl:otherwise>
</xsl:choose>

<xsl:choose>
    <xsl:when test="(/root/SubRoot[Section = 'B'])">
    //call some template
    </xsl:when>
<xsl:otherwise>
//some template
</xsl:otherwise>
</xsl:choose>

Each time my first when will get executed its not coming inside the second when condition.

Could you please help me how the both condition will get executed?is it right approach in terms of performance?

Any Suggestion approach must be appreciated.

Try this,

XSL

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns1="http://locomotive/bypass/docx">
<xsl:output method="xml" version="1.0" encoding="UTF-8"
    indent="yes" />
<xsl:strip-space elements="*" />

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()" />
    </xsl:copy>
</xsl:template>

<xsl:template match="SubRoot">
    <xsl:choose>
        <xsl:when test="Section = 'A'">
            <!-- your logic for A -->
            <A></A>
        </xsl:when>
        <xsl:otherwise>
            <!-- your logic for B -->
            <B></B>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

XML

<root>
<SubRoot>
    <type>A</type>
    <mand>Y</mand>
    <Section>B</Section>
</SubRoot>
<SubRoot>
    <type>A</type>
    <mand>Y</mand>
    <Section>A</Section>
</SubRoot>

Demo link : http://xsltransform.net/ejivdHb/15

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM