开发者

xsl: decision value from element to attribute

I want to use XSL to convert XML to another XML

The input xml contains the following element

<Vi开发者_Python百科ewSideIndicator>0</ViewSideIndicator>

which need to be converted to the following

<ImageViewDetail ViewSideIndicator="Front"/>

in the input file, if the value is "0", then it should be "Front" in the output and if the value is "1", then it should be "Back" in the output

I know that we can use <xsl:choose> to make the value based on a decision, but i'm not sure how to do it for this case.


In the template (assuming that the current source context is the ViewSideIndicator element):

<ImageViewDetail>
    <xsl:attribute name="ViewSideIndicator">
        <xsl:choose>
            <xsl:when test="text()='0'">Front</xsl:when>
            <xsl:when test="text()='1'">Back</xsl:when>
        </xsl:choose>
    </xsl:attribute>
</ImageViewDetail>


Do you mean something like this (or a version of it as a template)?

<ImageViewDetail>
    <xsl:choose>
        <xsl:when test="ViewSideIndicator=0">
            <xsl:attribute name="ViewSideIndicator">Front Gray</xsl:attribute>
        </xsl:when>
        <xsl:otherwise>
            <xsl:attribute name="ViewSideIndicator">Back Gray</xsl:attribute>
        </xsl:otherwise>
    </xsl:choose>
</ImageViewDetail>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜