2017-06-29 85 views
0

您好所有(请原谅我的亵渎提前,因为我不就这些议题确实娴熟而努力学习)XML映射:通过分标签组织

我卡上的东西,应该是简单的:

我有图片标签看起来像这样一个基本的文件的输入:

<PHOTO1> 
http://URL.COM/BCD 
</PHOTO1> 
<PHOTO2> 
http://URL.COM/CBC 
</PHOTO2> 
<PHOTO3> 
http://URL.COM/ABC 
</PHOTO3> 

和映射对其进行解码,上面写着:

<attachments> 
    <xsl:for-each select="node()[starts-with(name(), 'PHOTO')]"><image><xsl:value-of select="." /></image></xsl:for-each> 
</attachments> 

上传是按字母顺序进行,我不能用,我真的需要它来显示照片1首,比2等

任何想法,我怎么能做到这一点?

+0

A [MCVE]你的输出将是有益的。 – zx485

回答

0

排序基于标签名称为重点的输出,可以实现这样的:

<xsl:template match="/root"> 
    <attachments> 
    <xsl:for-each select="node()[starts-with(name(), 'PHOTO')]"> 
     <xsl:sort select="name()" />    <!-- name() as key --> 
     <image><xsl:value-of select="." /></image> 
    </xsl:for-each> 
    </attachments> 
</xsl:template>