Xslt 测试前一个元素的值是否与每个循环中的当前值相同
我有一个xml文件,其中名为identifier的元素可以出现1次以上。存储在这些标识符元素中的值可以是文件名、其他本地标识符、所谓的PID(数字:数字格式)和句柄(..url)。该信息可以以任何顺序出现,或者PID可以是1或句柄或文件名;这是随机的。我对PID和句柄感兴趣,数据在父元素记录中有以下3种PID和句柄场景: 1) PID仅在标识符元素套件中出现一次Xslt 测试前一个元素的值是否与每个循环中的当前值相同,xslt,xslt-2.0,Xslt,Xslt 2.0,我有一个xml文件,其中名为identifier的元素可以出现1次以上。存储在这些标识符元素中的值可以是文件名、其他本地标识符、所谓的PID(数字:数字格式)和句柄(..url)。该信息可以以任何顺序出现,或者PID可以是1或句柄或文件名;这是随机的。我对PID和句柄感兴趣,数据在父元素记录中有以下3种PID和句柄场景: 1) PID仅在标识符元素套件中出现一次 2) 句柄在标识符元素组中只出现一次 3) PID和句柄在标识符元素套件中都出现一次 在场景1中,我想将前缀“”添加到PID中,并将该
2) 句柄在标识符元素组中只出现一次
3) PID和句柄在标识符元素套件中都出现一次 在场景1中,我想将前缀“”添加到PID中,并将该值放入identifier元素中,然后添加一个元素源,在该元素源中我基于PID构造url 在场景2中,我只想将identifier字段的值带到新xml文件中的同一标识符,并在新的源元素中基于此句柄构造url 在场景3中,我想选择PID或句柄,但不能同时选择两者。假设我只想要句柄,而不是PID,然后我做场景2 当同时存在一个PID和一个句柄时,我有2个标识符和2个源元素,我不确定如何更改它,使它只执行场景2 我是xslt新手,不知道自己做错了什么。我尝试了前面的同级和每个和选择的变体,但是场景3的结果总是2个标识符元素和2个源元素 谢谢你的帮助 下面是xml的一个示例:
<record>
<identifier>200003:93939393</identifier>
<identifier>sampleFilename.jpg</identifier>
<identifier>otherLocalidentifier</identifier>
<identifier>hdl.handle.net/11134/200003:93939393</identifier>
</record>
<record>
<identifier>otherfilename.tiff</identifier>
<identifier>hdl.handle.net/11134/50003:93939393</identifier>
</record>
<record>
<identifier>somelocal name</identifier>
<identifier>94949:93999393</identifier>
</record>
200003:93939393
sampleFilename.jpg
其他本地标识符
hdl.handle.net/11134/200003:9393
otherfilename.tiff
hdl.handle.net/11134/50003:9393
本地名字
94949:93999393
在这个xml中,标识符还有其他值,标识符元素的数量是随机的,PID和句柄可以以任何顺序出现
我想要的输出是在新xml文件中始终有1个标识符和1个源元素:
<record>
<identifier>hdl.handle.net/11134/200003:93939393</identifier>
<source>200003:93939393/TN</source>
</record>
<record>
<identifier>hdl.handle.net/11134/50003:93939393</identifier>
<source>50003:93939393/TN</source>
</record>
<record>
<identifier>http://hdl.handle.net/11134/94949:93999393</identifier>
<source>94949:93999393/TN</source>
</record>
<xsl:template match="identifier">
<xsl:variable name="idvalue">
<xsl:choose>
<xsl:when test="contains(., 'http://hdl.handle.net/')">
<xsl:value-of select="normalize-space(.)"/>
</xsl:when>
<xsl:when test="matches(., '^\d{5,10}[:]\d*$')">
<xsl:text>http://hdl.handle.net/11134/</xsl:text>
<xsl:value-of select="normalize-space(.)"/>
</xsl:when>
<xsl:otherwise/>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="$idvalue[1]"></xsl:value-of>
hdl.handle.net/11134/200003:9393
200003:9393/TN
hdl.handle.net/11134/50003:9393
50003:9393/吨
http://hdl.handle.net/11134/94949:93999393
94949:93999393/TN
http://hdl.handle.net/11134/
I.正确的XSLT 2.0转换:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="vPat"
select="'(^\d{5,10}:\d+$)|(^hdl.handle.net/11134/\d{5,10}:\d+$)'"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="record/*[matches(., $vPat)][1]">
<identifier>
<xsl:value-of select="replace(.,'^(.*?)(\d{5,10}:\d+)$','hdl.handle.net/11134/$2')"/>
</identifier>
<source>
<xsl:value-of select="replace(.,'^(.*?)(\d{5,10}:\d+)$', '$2/TN')"/>
</source>
</xsl:template>
<xsl:template match="record/*" priority="0"/>
</xsl:stylesheet>
<t>
<record>
<identifier>other/Local/12345:67/identifier</identifier>
<identifier>200003:93939393</identifier>
<identifier>sampleFilename.jpg</identifier>
<identifier>hdl.handle.net/11134/200003:93939393</identifier>
</record>
<record>
<identifier>Some/50003:</identifier>
<identifier>otherfilename.tiff</identifier>
<identifier>hdl.handle.net/11134/50003:93939393</identifier>
</record>
<record>
<identifier>somelocal name</identifier>
<identifier>94949:93999393</identifier>
</record>
</t>
<t>
<record>
<identifier>hdl.handle.net/11134/200003:93939393</identifier>
<source>200003:93939393/TN</source>
</record>
<record>
<identifier>hdl.handle.net/11134/50003:93939393</identifier>
<source>50003:93939393/TN</source>
</record>
<record>
<identifier>hdl.handle.net/11134/94949:93999393</identifier>
<source>94949:93999393/TN</source>
</record>
</t>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template priority="3" match=
"record/*[floor(substring-before(., ':')) = substring-before(., ':')
and floor(substring-after(., ':')) = substring-after(., ':')
]">
<identifier><xsl:value-of select="concat('hdl.handle.net/11134/',.)"/></identifier>
<source><xsl:value-of select="concat(., '/TN')"/></source>
</xsl:template>
<xsl:template match=
"record[not(*[floor(substring-before(., ':')) = substring-before(., ':')
and floor(substring-after(., ':')) = substring-after(., ':')
]
)]
/*[starts-with(., 'hdl.handle.net/11134/')]">
<xsl:copy-of select="."/>
<source><xsl:value-of select="
concat(substring-after(., 'hdl.handle.net/11134/'), '/TN')"/></source>
</xsl:template>
<xsl:template match="text() |identifier"/>
</xsl:stylesheet>
<t>
<record>
<identifier>hdl.handle.net/11134/200003:93939393</identifier>
<source>200003:93939393/TN</source>
</record>
<record>
<identifier>hdl.handle.net/11134/50003:93939393</identifier>
<source>50003:93939393/TN</source>
</record>
<record>
<identifier>hdl.handle.net/11134/94949:93999393</identifier>
<source>94949:93999393/TN</source>
</record>
</t>
应用于以下XML文档时:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="vPat"
select="'(^\d{5,10}:\d+$)|(^hdl.handle.net/11134/\d{5,10}:\d+$)'"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="record/*[matches(., $vPat)][1]">
<identifier>
<xsl:value-of select="replace(.,'^(.*?)(\d{5,10}:\d+)$','hdl.handle.net/11134/$2')"/>
</identifier>
<source>
<xsl:value-of select="replace(.,'^(.*?)(\d{5,10}:\d+)$', '$2/TN')"/>
</source>
</xsl:template>
<xsl:template match="record/*" priority="0"/>
</xsl:stylesheet>
<t>
<record>
<identifier>other/Local/12345:67/identifier</identifier>
<identifier>200003:93939393</identifier>
<identifier>sampleFilename.jpg</identifier>
<identifier>hdl.handle.net/11134/200003:93939393</identifier>
</record>
<record>
<identifier>Some/50003:</identifier>
<identifier>otherfilename.tiff</identifier>
<identifier>hdl.handle.net/11134/50003:93939393</identifier>
</record>
<record>
<identifier>somelocal name</identifier>
<identifier>94949:93999393</identifier>
</record>
</t>
<t>
<record>
<identifier>hdl.handle.net/11134/200003:93939393</identifier>
<source>200003:93939393/TN</source>
</record>
<record>
<identifier>hdl.handle.net/11134/50003:93939393</identifier>
<source>50003:93939393/TN</source>
</record>
<record>
<identifier>hdl.handle.net/11134/94949:93999393</identifier>
<source>94949:93999393/TN</source>
</record>
</t>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template priority="3" match=
"record/*[floor(substring-before(., ':')) = substring-before(., ':')
and floor(substring-after(., ':')) = substring-after(., ':')
]">
<identifier><xsl:value-of select="concat('hdl.handle.net/11134/',.)"/></identifier>
<source><xsl:value-of select="concat(., '/TN')"/></source>
</xsl:template>
<xsl:template match=
"record[not(*[floor(substring-before(., ':')) = substring-before(., ':')
and floor(substring-after(., ':')) = substring-after(., ':')
]
)]
/*[starts-with(., 'hdl.handle.net/11134/')]">
<xsl:copy-of select="."/>
<source><xsl:value-of select="
concat(substring-after(., 'hdl.handle.net/11134/'), '/TN')"/></source>
</xsl:template>
<xsl:template match="text() |identifier"/>
</xsl:stylesheet>
<t>
<record>
<identifier>hdl.handle.net/11134/200003:93939393</identifier>
<source>200003:93939393/TN</source>
</record>
<record>
<identifier>hdl.handle.net/11134/50003:93939393</identifier>
<source>50003:93939393/TN</source>
</record>
<record>
<identifier>hdl.handle.net/11134/94949:93999393</identifier>
<source>94949:93999393/TN</source>
</record>
</t>
其他/本地/12345:67/标识符
200003:93939393
sampleFilename.jpg
hdl.handle.net/11134/200003:9393
部分/50003:
otherfilename.tiff
hdl.handle.net/11134/50003:9393
本地名字
94949:93999393
生成所需的正确结果:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="vPat"
select="'(^\d{5,10}:\d+$)|(^hdl.handle.net/11134/\d{5,10}:\d+$)'"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="record/*[matches(., $vPat)][1]">
<identifier>
<xsl:value-of select="replace(.,'^(.*?)(\d{5,10}:\d+)$','hdl.handle.net/11134/$2')"/>
</identifier>
<source>
<xsl:value-of select="replace(.,'^(.*?)(\d{5,10}:\d+)$', '$2/TN')"/>
</source>
</xsl:template>
<xsl:template match="record/*" priority="0"/>
</xsl:stylesheet>
<t>
<record>
<identifier>other/Local/12345:67/identifier</identifier>
<identifier>200003:93939393</identifier>
<identifier>sampleFilename.jpg</identifier>
<identifier>hdl.handle.net/11134/200003:93939393</identifier>
</record>
<record>
<identifier>Some/50003:</identifier>
<identifier>otherfilename.tiff</identifier>
<identifier>hdl.handle.net/11134/50003:93939393</identifier>
</record>
<record>
<identifier>somelocal name</identifier>
<identifier>94949:93999393</identifier>
</record>
</t>
<t>
<record>
<identifier>hdl.handle.net/11134/200003:93939393</identifier>
<source>200003:93939393/TN</source>
</record>
<record>
<identifier>hdl.handle.net/11134/50003:93939393</identifier>
<source>50003:93939393/TN</source>
</record>
<record>
<identifier>hdl.handle.net/11134/94949:93999393</identifier>
<source>94949:93999393/TN</source>
</record>
</t>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template priority="3" match=
"record/*[floor(substring-before(., ':')) = substring-before(., ':')
and floor(substring-after(., ':')) = substring-after(., ':')
]">
<identifier><xsl:value-of select="concat('hdl.handle.net/11134/',.)"/></identifier>
<source><xsl:value-of select="concat(., '/TN')"/></source>
</xsl:template>
<xsl:template match=
"record[not(*[floor(substring-before(., ':')) = substring-before(., ':')
and floor(substring-after(., ':')) = substring-after(., ':')
]
)]
/*[starts-with(., 'hdl.handle.net/11134/')]">
<xsl:copy-of select="."/>
<source><xsl:value-of select="
concat(substring-after(., 'hdl.handle.net/11134/'), '/TN')"/></source>
</xsl:template>
<xsl:template match="text() |identifier"/>
</xsl:stylesheet>
<t>
<record>
<identifier>hdl.handle.net/11134/200003:93939393</identifier>
<source>200003:93939393/TN</source>
</record>
<record>
<identifier>hdl.handle.net/11134/50003:93939393</identifier>
<source>50003:93939393/TN</source>
</record>
<record>
<identifier>hdl.handle.net/11134/94949:93999393</identifier>
<source>94949:93999393/TN</source>
</record>
</t>
hdl.handle.net/11134/200003:9393
200003:9393/TN
hdl.handle.net/11134/50003:9393
50003:9393/吨
hdl.handle.net/11134/94949:93999393
94949:93999393/TN
II。此XSLT 1.0转换:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="vPat"
select="'(^\d{5,10}:\d+$)|(^hdl.handle.net/11134/\d{5,10}:\d+$)'"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="record/*[matches(., $vPat)][1]">
<identifier>
<xsl:value-of select="replace(.,'^(.*?)(\d{5,10}:\d+)$','hdl.handle.net/11134/$2')"/>
</identifier>
<source>
<xsl:value-of select="replace(.,'^(.*?)(\d{5,10}:\d+)$', '$2/TN')"/>
</source>
</xsl:template>
<xsl:template match="record/*" priority="0"/>
</xsl:stylesheet>
<t>
<record>
<identifier>other/Local/12345:67/identifier</identifier>
<identifier>200003:93939393</identifier>
<identifier>sampleFilename.jpg</identifier>
<identifier>hdl.handle.net/11134/200003:93939393</identifier>
</record>
<record>
<identifier>Some/50003:</identifier>
<identifier>otherfilename.tiff</identifier>
<identifier>hdl.handle.net/11134/50003:93939393</identifier>
</record>
<record>
<identifier>somelocal name</identifier>
<identifier>94949:93999393</identifier>
</record>
</t>
<t>
<record>
<identifier>hdl.handle.net/11134/200003:93939393</identifier>
<source>200003:93939393/TN</source>
</record>
<record>
<identifier>hdl.handle.net/11134/50003:93939393</identifier>
<source>50003:93939393/TN</source>
</record>
<record>
<identifier>hdl.handle.net/11134/94949:93999393</identifier>
<source>94949:93999393/TN</source>
</record>
</t>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template priority="3" match=
"record/*[floor(substring-before(., ':')) = substring-before(., ':')
and floor(substring-after(., ':')) = substring-after(., ':')
]">
<identifier><xsl:value-of select="concat('hdl.handle.net/11134/',.)"/></identifier>
<source><xsl:value-of select="concat(., '/TN')"/></source>
</xsl:template>
<xsl:template match=
"record[not(*[floor(substring-before(., ':')) = substring-before(., ':')
and floor(substring-after(., ':')) = substring-after(., ':')
]
)]
/*[starts-with(., 'hdl.handle.net/11134/')]">
<xsl:copy-of select="."/>
<source><xsl:value-of select="
concat(substring-after(., 'hdl.handle.net/11134/'), '/TN')"/></source>
</xsl:template>
<xsl:template match="text() |identifier"/>
</xsl:stylesheet>
<t>
<record>
<identifier>hdl.handle.net/11134/200003:93939393</identifier>
<source>200003:93939393/TN</source>
</record>
<record>
<identifier>hdl.handle.net/11134/50003:93939393</identifier>
<source>50003:93939393/TN</source>
</record>
<record>
<identifier>hdl.handle.net/11134/94949:93999393</identifier>
<source>94949:93999393/TN</source>
</record>
</t>
应用于同一XML文档时,再次生成所需的正确结果:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="vPat"
select="'(^\d{5,10}:\d+$)|(^hdl.handle.net/11134/\d{5,10}:\d+$)'"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="record/*[matches(., $vPat)][1]">
<identifier>
<xsl:value-of select="replace(.,'^(.*?)(\d{5,10}:\d+)$','hdl.handle.net/11134/$2')"/>
</identifier>
<source>
<xsl:value-of select="replace(.,'^(.*?)(\d{5,10}:\d+)$', '$2/TN')"/>
</source>
</xsl:template>
<xsl:template match="record/*" priority="0"/>
</xsl:stylesheet>
<t>
<record>
<identifier>other/Local/12345:67/identifier</identifier>
<identifier>200003:93939393</identifier>
<identifier>sampleFilename.jpg</identifier>
<identifier>hdl.handle.net/11134/200003:93939393</identifier>
</record>
<record>
<identifier>Some/50003:</identifier>
<identifier>otherfilename.tiff</identifier>
<identifier>hdl.handle.net/11134/50003:93939393</identifier>
</record>
<record>
<identifier>somelocal name</identifier>
<identifier>94949:93999393</identifier>
</record>
</t>
<t>
<record>
<identifier>hdl.handle.net/11134/200003:93939393</identifier>
<source>200003:93939393/TN</source>
</record>
<record>
<identifier>hdl.handle.net/11134/50003:93939393</identifier>
<source>50003:93939393/TN</source>
</record>
<record>
<identifier>hdl.handle.net/11134/94949:93999393</identifier>
<source>94949:93999393/TN</source>
</record>
</t>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template priority="3" match=
"record/*[floor(substring-before(., ':')) = substring-before(., ':')
and floor(substring-after(., ':')) = substring-after(., ':')
]">
<identifier><xsl:value-of select="concat('hdl.handle.net/11134/',.)"/></identifier>
<source><xsl:value-of select="concat(., '/TN')"/></source>
</xsl:template>
<xsl:template match=
"record[not(*[floor(substring-before(., ':')) = substring-before(., ':')
and floor(substring-after(., ':')) = substring-after(., ':')
]
)]
/*[starts-with(., 'hdl.handle.net/11134/')]">
<xsl:copy-of select="."/>
<source><xsl:value-of select="
concat(substring-after(., 'hdl.handle.net/11134/'), '/TN')"/></source>
</xsl:template>
<xsl:template match="text() |identifier"/>
</xsl:stylesheet>
<t>
<record>
<identifier>hdl.handle.net/11134/200003:93939393</identifier>
<source>200003:93939393/TN</source>
</record>
<record>
<identifier>hdl.handle.net/11134/50003:93939393</identifier>
<source>50003:93939393/TN</source>
</record>
<record>
<identifier>hdl.handle.net/11134/94949:93999393</identifier>
<source>94949:93999393/TN</source>
</record>
</t>
hdl.handle.net/11134/200003:9393
200003:9393/TN
hdl.handle.net/11134/50003:9393
50003:9393/吨
hdl.handle.net/11134/94949:93999393
94949:93999393/TN
假设您的正则表达式唯一标识PID,我建议您这样尝试:
XSLT2.0
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="record">
<xsl:variable name="pid" select="(identifier/tokenize(., '/')[matches(., '^\d{5,10}[:]\d*$')])[1]"/>
<xsl:copy>
<identifier><xsl:value-of select="concat('hdl.handle.net/11134/', $pid)"/></identifier>
<source><xsl:value-of select="concat($pid, '/TN')"/></source>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
演示:欢迎使用堆栈溢出。很多人会很乐意帮忙,但很少有人会为您编写符合规范的代码。如果你先尝试一下自己,然后问一些关于你被困在哪里的问题,你会得到最好的帮助。您可以将您的问题添加到中,特别是添加您的XSLT尝试。您是否可以扩展此操作所需的逻辑?似乎需要首先选择包含“:”的第一个标识符,使用“/”作为分隔符标记它,然后获取最后一个标记。对吗?--+请指出您正在使用的XSLT处理器。我已经尝试了许多解决方案(前面的同级、嵌套if语句)。当PID和句柄出现在中时,我不明白如何只在其中一个上执行操作,而不在另一个上执行操作。问题是冒号可能出现在既不是PID也不是句柄的其他值中。我使用的是xslt版本2,恐怕这不能回答我的问题。在美国,问题不在于“如何只在一个方面做事情,而不是在另一方面”。这其实很琐碎。真正的问题是如何识别包含字符串中的PID子字符串,以便将其提取出来。如果其他子字符串也可以包含冒号,那么您需要提供一些仅适用于PID而不适用于其他子字符串的条件-例如仅包含数字和/或组件的最小/最大长度等@Jennifer,这是一个好问题!请参阅我的答案,了解XSLT2.0和XSLT1.0中的正确解决方案。请注意,另一个答案在我的答案的XML文档上应用其转换时会产生错误的结果。您应该说明OP没有给出的假设,例如“一个记录将始终包含一个仅包含PID的标识符,和/或一个包含PID的标识符,前面有一个已知字符串”“用冒号分隔的任何两组数字都是PID的。”@michael.hor257k,当然,我从来没有做过这些假设!