English 中文(简体)
我如何在使用SLT的<xs:list”中找到内容?
原标题:How do I find the number of elements in a <xs:list> using XSLT?

我有一个XML图形,包含以下类型:

<xs:simpleType name="valuelist">
  <xs:list itemType="xs:double"/>
</xs:simpleType>

样本XML碎片将:

<values>1 2 3.2 5.6</values>

在一项《制止危及海上航行安全非法行为公约》的转变中,我如何掌握名单上的内容?

我如何回避这些内容?

最佳回答

I. XPath 2.0 (XSLT 2.0) Solutions:

count(tokenize(.,    ))

II. XPath 1.0 (XSLT 1.0) solution:

 string-length()
-
 string-length(translate(normalize-space(),    ,   ))
+ 1

As for iteration over the items of this list:

  1. In XPath 2.0 / XSLT 2.0 just use the above XPath 2.0 expression as the value of a select attribute:

纽约总部

 for $i in tokenize(.,    ),
     $n in number($i)
  return
    yourXPathExpression

纽约总部

2. In XSLT 1.0 you need to have some more code for splitting/tokenization. There are several good answers to this question (part of them mine) 纽约总部 just search for something like "xslt split a string"

问题回答

如果名单严格限时,你可以按长处计算面积。

<values>1 2 3.2 5.6</values>

XSLT:

<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="/">
        <xsl:value-of select="string-length(values) 
                      - string-length(translate(values,    ,   )) + 1"/>
    </xsl:template>

</xsl:stylesheet>

挑拨你必须分拨这种扼杀。 在SO中有很多例子。

在软件转换中,使用<代码>(数据(价值))

With a little imagination you can write your own split function :

<xsl:stylesheet version =  1.0  xmlns:xsl= http://www.w3.org/1999/XSL/Transform >
    <xsl:output method= text />

    <xsl:template name="split-list">
    <xsl:param name="list" />
    <xsl:param name="separator"/>
    <xsl:variable name="newlist" select="concat(normalize-space($list), $separator)" /> 
    <xsl:variable name="first" select="substring-before($newlist, $separator)" /> 
    <xsl:variable name="remaining" select="substring-after($newlist, $separator)" />
            <xsl:message terminate="no">
            <xsl:value-of select="$first" />
        </xsl:message>

    <xsl:if test="$remaining">
        <xsl:call-template name="split-list">
          <xsl:with-param name="list" select="$remaining" />
                    <xsl:with-param name="separator" select="$separator"/>
        </xsl:call-template>
    </xsl:if>
</xsl:template>

<xsl:template match="/">
    <xsl:variable name="myList">
            1 2 3.2 5.6
    </xsl:variable>
        <xsl:call-template name="split-list">
            <xsl:with-param name="list" select="$myList" />
            <xsl:with-param name="separator">
                <xsl:text> </xsl:text>
            </xsl:with-param>
        </xsl:call-template>
</xsl:template>
</xsl:stylesheet>

产出:

[xslt] Loading stylesheet D:ToolsStackOverFlow	est.xslt
[xslt] 1
[xslt] 2
[xslt] 3.2
[xslt] 5.6




相关问题
How to validate DataTable with XML Schema?

Does anyone know how to validate a DataTable against a particular DataTable XSD (Schema)? Which would be the best performance-optimized way of doing this? For example: <?xml version="1.0" ...

Deprecated XML validation code problem C#

I m trying to figure out how to correct his deprecated xml schema validation code. public static bool ValidateXml(string xmlFilename, string schemaFilename) { ⁞ //Forward stream reading ...

Getting an object representation of an .XSD file in Java

What is the easiest way to obtain a statically typed representation of an XML schema (.XSD) in Java? More specifically I want to be able to programatically traverse all defined simpleType:s and ...

xmlserializer validation

I m using XmlSerializer to deserialize Xml achives. But I found the class xsd.exe generated only offers capability to read the xml, but no validation. For example, if one node is missing in a document,...

regex for four-digit numbers (or "default")

I need a regex for four-digit numbers separated by comma ("default" can also be a value). Examples: 6755 3452,8767,9865,8766,3454 7678,9876 1234,9867,6876,9865 default Note: "default" ...

热门标签