XSLT aggregating XML tag values and storing new tag

前端 未结 1 913
慢半拍i
慢半拍i 2021-01-29 16:01

I\'m new to xslt and trying to process below XML using XSLT :



F<         


        
相关标签:
1条回答
  • 2021-01-29 16:37

    Since XSLT variables are immutable, I'm unable perform below operation.

    I don't see what variables, immutable or not, have to do with it. This is just straightforward XSLT:

    XSLT 1.0

    <xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
    
    <xsl:template match="/xml">
        <xsl:for-each select="characters">
            <word>
                <value>
                    <xsl:for-each select="char">
                        <xsl:value-of select="."/>
                    </xsl:for-each>
                </value>
                <coordinates>
                    <xsl:value-of select="char[1]/@a"/>
                    <xsl:text> </xsl:text>
                    <xsl:value-of select="char[1]/@b"/>
                    <xsl:text> </xsl:text>
                    <xsl:value-of select="char[last()]/@y"/>
                    <xsl:text> </xsl:text>
                    <xsl:value-of select="char[last()]/@z"/>
                </coordinates>
                <avgWeight>
                    <xsl:value-of select="sum(characters/char/@weight) div count(characters/char) "/>
                </avgWeight>
            </word>
        </xsl:for-each>
    </xsl:template>
    
    </xsl:stylesheet>
    
    0 讨论(0)
提交回复
热议问题