XSL密钥,从格式错误的数据中创建密钥

克拉斯·布隆伯格(Klas Blomberg)

我有这个XML文件,想统计每个callNumber附加了多少个项目-如果我的数据格式正确,这是一个非常容易的任务:-(

问题是我想为其中一个创建密钥

a)整个callNumber(如果其中不包含空格),或者

b)如果callNumber中有空格,则空格之前的部分应将'12'包含在与'12 34'相同的键中

到目前为止,我拒绝的解决方案:

子字符串-无效,因为Callnumber的长度不同

空格前的子字符串-无效,因为某些callNumbers不包含空格。

这有可能吗,还是我的数据太怪异了?我只能使用XSL 1.0,没有扩展名

<?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="countitempercall.xsl"?>
    <report>
        <catalog>
            <call>
                <callNumber>12</callNumber>
                <item>
                    <itemID>305810</itemID>
                </item>
            </call>
        </catalog>
        <catalog>
            <call>
                <callNumber>12 34</callNumber>
                <item>
                    <itemID>305811</itemID>
                </item>
            </call>
        </catalog>
        <catalog>
            <call>
                <callNumber>567A89</callNumber>
                <item>
                    <itemID>305812</itemID>
                </item>
            </call>
        </catalog>
        <catalog>
            <call>
                <callNumber>567A89 Abc</callNumber>
                <item>
                    <itemID>305813</itemID>
                </item>
                <item>
                    <itemID>305814</itemID>
                </item>
            </call>
        </catalog>
    </report>

到目前为止我的样式表

<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:key name="shelf" match="call" use="callNumber"/>

<xsl:template match="/">
    <callNumberUsage>

        <xsl:for-each select="//call[generate-id(.)=generate-id(key('shelf', callNumber)[1])]">

        <xsl:sort select="callNumber"/>

            <callNumberline>
                <callNumber><xsl:value-of select="callNumber"/></callNumber>
                <numberOfItems><xsl:value-of select="count(key('shelf', callNumber)/item)"/></numberOfItems>
            </callNumberline>

        </xsl:for-each>
    </callNumberUsage>
</xsl:template>

</xsl:stylesheet>
C队

您可以substring-before与组合使用concat以在末尾添加一个空格callNumber

<xsl:key name="shelf" match="call" use="substring-before(concat(callNumber, ' '), ' ')"/>

在电话号码有空格的情况下,第二个空格不会影响它。在没有空格的情况下,最终将根据需要获得整数。

试试这个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:key name="shelf" match="call" use="substring-before(concat(callNumber, ' '), ' ')"/>

<xsl:template match="/">
    <callNumberUsage>

        <xsl:for-each select="//call[generate-id(.)=generate-id(key('shelf', substring-before(concat(callNumber, ' '), ' '))[1])]">

        <xsl:sort select="callNumber"/>

            <callNumberline>
                <callNumber><xsl:value-of select="callNumber"/></callNumber>
                <numberOfItems><xsl:value-of select="count(key('shelf', substring-before(concat(callNumber, ' '), ' '))/item)"/></numberOfItems>
            </callNumberline>

        </xsl:for-each>
    </callNumberUsage>
</xsl:template>

</xsl:stylesheet>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Spring JPA-在MySQL数据库上创建预创建密钥时出现错误休眠

Google数据存储区无效密钥错误

如何在Terraform中创建SSH密钥?

创建数据存储区的成本。密钥:将密钥存储在结构中,而不存储ID和从数据存储区中获取数据

在请求中设置了密钥的dailyLimitExceededUnreg错误

在C#中创建我的对称密钥

Gitlab密钥格式问题

在xslt模板中创建密钥

在kubernetes中创建SSH密钥文件

请在执行此操作之前在数据库中创建主密钥或在会话中打开主密钥

Flink错误-密钥组不在KeyGroupRange中

使用R行中存储的密钥将数据帧从宽格式转换为长格式

即使创建了密钥,Masonite也会抛出无效的密钥错误

创建RSA密钥对并在Azure密钥库中检索公共密钥

为什么WebhookResponse构建器在json中创建错误的密钥?

创建Terraform资源aws_key_pair错误:InvalidKey.Format:密钥不是有效的OpenSSH公钥格式

在Python中创建Azure密钥库

Terraform-错误:[DEBUG]在输入字节1处创建SSH密钥非法base64数据

设置PuTTY在GitLab中创建的SSH密钥

在github中创建ssh密钥

如果嵌套哈希中不存在密钥,则创建密钥

加密中密钥使用错误

从种子/密钥创建大型数组/数据

使用 xaml 中的密钥创建实例

如何将用户提交的数据放入新的 Firebase 密钥中,密钥仅在单击提交按钮传递数据时创建

KSQL Kafka 密钥格式

Facebook 密钥哈希生成错误格式

离子:jarsigner 错误:java.lang.RuntimeException:密钥库加载:无效的密钥库格式

InvalidKeyException: 无效的密钥格式