Xml 如何获取特定的元素值

Xml 如何获取特定的元素值,xml,xslt,Xml,Xslt,我有以下XML: 当我使用当前元素的select值时,它为我提供了ID和玻璃元素的32131DK值 在我的输出中,我只想得到ID元素后面的数值321 无法更改xml输入,因为它来自制造商 我的XSLT: <xsl:element name="ProfileSpecification"> <xsl:for-each select="Supplement/ID"> <xsl:value-of select="."/> </xs

我有以下XML:

当我使用当前元素的select值时,它为我提供了ID和玻璃元素的32131DK值

在我的输出中,我只想得到ID元素后面的数值321

无法更改xml输入,因为它来自制造商

我的XSLT:

<xsl:element name="ProfileSpecification">
    <xsl:for-each select="Supplement/ID">
        <xsl:value-of select="."/>
    </xsl:for-each> </element>
我得到的输出:

<ProfileSpecification>32131DK</ProfileSpecification>
我想要的输出:

<ProfileSpecification>321</ProfileSpecification>

您的方法不起作用,因为

<xsl:value-of select="."/>
XSLT样式表

XML输出


你不应该简单地匹配/。。。如果您可以直接匹配和处理重要的元素。这是一个很有问题的建议,伊姆霍。任何重要元素的祖先都将由内置的模板规则处理-您可能很容易得到不希望被复制到输出中的文本。@michael.hor257k我同意,我想为这个特定的转换提供建议,但这并不清楚。我会编辑我的问题。谢谢你的回复。我会试着采纳你的建议。
<xsl:value-of select="."/>
<?xml version="1.0" encoding="UTF-8"?>
<root>
    <Supplement>
        <ID>321
        <SupplementType>
            <Glass>31DK</Glass>
        </SupplementType>
        </ID>
    </Supplement>
    <Supplement>
        <ID>425
        <SupplementType>
            <Glass>444d</Glass>
        </SupplementType>
        </ID>
    </Supplement>
</root>
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:output method="xml" encoding="UTF-8" indent="yes" />

    <xsl:template match="/root">
        <xsl:copy>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="Supplement">
        <ProfileSpecification>
            <xsl:value-of select="normalize-space(ID/text()[1])"/>
        </ProfileSpecification>
    </xsl:template>

</xsl:transform>
<?xml version="1.0" encoding="UTF-8"?>
<root>
    <ProfileSpecification>321</ProfileSpecification>
    <ProfileSpecification>425</ProfileSpecification>
</root>