XSL 数字生成 ID() [英] XSL numeric generate-id()

查看:25
本文介绍了XSL 数字生成 ID()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

XSL 如何使用 XSL 为 XML 文档中的每个元素生成唯一的 id 属性,其中 id 必须是数字?下面的 XLS 有效,只是生成的 id 是字母数字,我需要数字?

How can XSL generate a unique id attribute for every element in an XML document using XSL where the id must be numeric? The XLS below works except that the generated ids are alphanumeric and I need numeric?

<?xml version='1.0' encoding='utf-8'?>  
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
    xmlns:msxsl='urn:schemas-microsoft-com:xslt' exclude-result-prefixes='msxsl'>  
    <xsl:output method='xml' indent='yes'/>  
    <xsl:template match='*'>  
      <xsl:copy>  
        <xsl:attribute name='ElementID'>  
          <xsl:value-of select='generate-id()'/>  
        </xsl:attribute>  
        <xsl:apply-templates/>  
      </xsl:copy>  
    </xsl:template>    
</xsl:stylesheet>  

谢谢.

推荐答案

您可以随时使用:

     concat(count(ancestor::node()),
           '00000000',
           count(preceding::node()))

Michael Kay 等知识渊博的人警告说 效率不高(有时为 O(N^2)),如果可能.

Knowledgeable people such as Michael Kay warn that <xsl:number/> is not efficient (sometimes O(N^2)) and should be avoided if possible.

这篇关于XSL 数字生成 ID()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆