输入
<row>
<name-prf>Prokofiev, Serge (piano); Adolph Bolm (dancer)</name-prf>
</row>
期望输出
<subject>
<name type="personal">
<namePart>Prokofiev, Serge (piano)</namePart>
<role>
<roleTerm type="code" authority="marcrelator">prf</roleTerm>
</role>
</name>
</subject>
<subject>
<name type="personal">
<namePart>Adolph Bolm (dancer)</namePart>
<role>
<roleTerm type="code" authority="marcrelator">prf</roleTerm>
</role>
</name>
</subject>
当前代码
<subject>
<name type="personal">
<namePart>
<xsl:value-of select="name-prf"/>
</namePart>
<role>
<roleTerm type="code" authority="marcrelator">prf</roleTerm>
</role>
</name>
</subject>
我一直在使用价值而不是单独的模板,因为订单与初始表格非常不同,但我觉得这里的解决方案可能会多次强制模板调用?
答案 0 :(得分:1)
我只是不太确定如何在此上下文中使用tokenize。我可以用 2.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:template match="row">
<xsl:for-each select="tokenize(name-prf, '; ')">
<subject>
<name type="personal">
<namePart>
<xsl:value-of select="."/>
</namePart>
<role>
<roleTerm type="code" authority="marcrelator">prf</roleTerm>
</role>
</name>
</subject>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
答案 1 :(得分:0)
如果您受限于XSLT 1.0,请将其添加为扩展功能:
public XPathNodeIterator Tokenize(string value, string separators)
{
XElement root = new XElement("Root");
string[] tokens = value.Split(separators.ToCharArray());
for (int i = 0; i < tokens.Length; i++)
{
root.Add(tokens[i]);
}
return root.CreateNavigator().Select("/");
}
答案 2 :(得分:0)
好的,tokenize是关键,我无法直接标记,但我可以使用参数进行标记,不知道为什么会产生影响:
<xsl:param name="seperator" select="'; '"/>
<xsl:for-each select="distinct-values(name-prf/tokenize(.,$seperator))">
<person><xsl:value-of select="."/></person>
</xsl:for-each>