我正在尝试在节点名称中提取“:”之后的字符串,并将其分配为字段名称,但是下面的我的XSLT似乎无法正常工作。
这是我的XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<oai_dc:dc xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/">
<dc:title>valley</dc:title>
<dc:creator>jhdjsdh</dc:creator>
<dc:subject>tree</dc:subject>
</oai_dc:dc>
XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/">
<xsl:template match="/">
<xsl:for-each select="oai_dc:dc/*">
<field>
<xsl:attribute name="name">
<xsl:value-of select="local-name()"/>
</xsl:attribute>
<xsl:value-of select="text()"/>
</field>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
我想用以上XSLT实现但无法使用:
<field name="title"> valley </field>
<field name="creator"> jhdjsdh</field>
<field name="subject"> tree </field>
我收到一个404,试图使用您指向freeformatter.com的链接,但是我确实尝试了xsltransform.net,并且您的样式表使用Xalan正常工作。 (尽管我确实向xsl:stylesheet添加了exclude-result-prefixes属性)。...
还请注意,您可以使用属性值模板(AVT)而不是xsl:attribute
来简化属性创建。
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"
exclude-result-prefixes="dc oai_dc">
<xsl:template match="/">
<xsl:for-each select="oai_dc:dc/*">
<field name="{local-name()}">
<xsl:value-of select="text()"/>
</field>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>