0
votes

I need to vary my same element by using the attribute value using the XSL:

My Input xml is:

<span class="Option">
<span class="AnswerText">Female</span>
</span>

XSL I used:

   <xsl:template match="span">
      <p><xsl:apply-templates/></p>
   </xsl:template>

Output I'm getting as:

<p><p>Female</p></p>

But I want the output be like:

<p><ph>Female</ph></p>

I need to vary the both span element by using the attribute value. Please suggest me the code. Thanks in advance

2

2 Answers

0
votes

You could use:

<xsl:template match="span[@class='Option']">
    <p>
        <xsl:apply-templates/>
    </p>
</xsl:template>

<xsl:template match="span[@class='AnswerText']">
    <ph>
        <xsl:apply-templates/>
    </ph>
</xsl:template>
0
votes

You can use axis to check if span has parent tag span and then apply templates accordingly

<xsl:template match="span">
        <xsl:choose>
            <xsl:when test="parent::span">
                <ph>
                    <xsl:apply-templates/>
                </ph>
            </xsl:when>
            <xsl:otherwise>
                <p>
                    <xsl:apply-templates/>
                </p>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

Output:

<p>
    <ph>Female</ph>
</p>