我有 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/轉換器。我在這里做錯了什么?
uj5u.com熱心網友回復:
因為你有xpath-default-namespace="http://purl.org/rss/1.0/modules/content/"。
您的 RSS 元素未系結到任何命名空間,它們位于“無命名空間”中。
但是由于您添加了默認的 XPath 命名空間屬性,它正在尋找系結到該命名空間的元素,但沒有找到。
uj5u.com熱心網友回復:
只需添加命名空間 content:
<?xml version="1.0" encoding="UTF-8"?>
<content: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#"
>
<content: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>
<content:item>
<content:title>ICYMI: Of Plimoth Plantation</content:title>
</content:item>
</content:channel>
</content:rss>
你得到輸出:
<update>
<add>
<doc>
<field name="tcngrams_title">ICYMI: Of Plimoth Plantation</field>
</doc>
</add>
</update>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/337080.html
上一篇:如何使用區塊鏈記仇
