XSLT解析工作错误



我有RSS提要,我的任务是将该提要解析为其他XML模式。我正在使用XSLT解析器。这里是我的rss提要和解析器:

<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
xmlns:georss="http://www.georss.org/georss"
xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
>
<channel>
<title>Vita Brevis</title>
<atom:link href="https://vitabrevis.americanancestors.org/feed/" rel="self" type="application/rss+xml"/>
<link>https://vitabrevis.americanancestors.org</link>
<description>A resource for family history from AmericanAncestors.org</description>
<lastBuildDate>Mon, 25 Oct 2021 16:23:50 +0000</lastBuildDate>
<language>en-US</language>
<sy:updatePeriod>
hourly
</sy:updatePeriod>
<sy:updateFrequency>
1
</sy:updateFrequency>
<generator>https://wordpress.org/?v=5.8.1</generator>
<site xmlns="com-wordpress:feed-additions:1">62574325</site>
<item>
<title>ICYMI: Of Plimoth Plantation</title>
</item>
</channel>
</rss>

XSLT和

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
version="2.0"
xpath-default-namespace="http://purl.org/rss/1.0/modules/content/"
exclude-result-prefixes="content">
<xsl:output method="xml" doctype-public="XSLT-compat" omit-xml-declaration="yes" 
encoding="UTF-8" indent="yes"/>

<xsl:template match="/">
<xsl:element name="update">
<xsl:apply-templates select="rss/channel/item"/>
</xsl:element>
</xsl:template>
<xsl:template match="rss/channel/item">
<xsl:element name="add">
<xsl:element name="doc">                   
<xsl:element name="field">
<xsl:attribute name="name">tcngrams_title</xsl:attribute>
<xsl:value-of select="title"/>
</xsl:element>           
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

期望的结果应该是

<update>
<add>
<doc>
<field name="tcngrams_title">ICYMI: Of Plimoth Plantation</field>
</doc>
</add>
</update>

但是我得到的只有<update />

我正在使用http://xsltransform.net/变压器。我哪里做错了?

因为你有xpath-default-namespace="http://purl.org/rss/1.0/modules/content/"

您的RSS元素没有绑定到任何名称空间,它们位于"无名称空间"中。

但是由于您添加了默认的XPath名称空间属性,所以它正在查找绑定到该名称空间的元素,但是没有找到。

相关内容

最新更新