我想创建一个具有RSS 2.0基本元素的数据馈送,如下所示:
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">
<channel>
<title>Clot3333333tory</title>
<description>Clot333333333333333holesale pricing and bulk ordering to consumers and businesses.</description>
<item>
<title>
<description>
<link> 我在XML文档上使用XSLT样式表来填充这个模板,遇到的一个问题是我想在XML文档中为完成的项目中的标记<description>使用一个名为<Caption>的标记。这个‘标题’字段是html格式的,我想把标题数据拉到‘描述’,但只是显示为文本,并删除所有的html标签。在样式表中这样做会是什么样子呢?
编辑:
传入的XML文件如下所示(只包含一个'item‘元素):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE StoreExport SYSTEM "http://store.yahoo.com/doc/dtd/StoreExport.dtd">
<StoreExport>
<Settings>
<Published timestamp="1297187196"/>
<Locale code="C" name="English" encoding="iso-8859-1"/>
<StoreName>Clo3333333nd.com</StoreName>
<Currency>USD</Currency>
<ShipMethods>
<ShipMethod>Ground</ShipMethod>
<ShipMethod>Two Day Delivery</ShipMethod>
<ShipMethod>One Day Delivery</ShipMethod>
<ShipMethod>3 Day</ShipMethod>
</ShipMethods>
<PayMethods>
<PayMethod>American Express</PayMethod>
<PayMethod>Discover</PayMethod>
<PayMethod>MasterCard</PayMethod>
<PayMethod>Visa</PayMethod>
<PayMethod>Diner's Club</PayMethod>
</PayMethods>
</Settings>
<Products>
<Product Id="agfasu">
<Code>3616a</Code>
<Description>Ageless Fashion Suit</Description>
<Url>http://www.clo333333nd.com/agfasu.html</Url>
<Thumb><img border=0 width=50 height=70 src=http://ep.yimg.33333333333st-27703333333618_2144_317652924></Thumb>
<Picture><img border=0 width=600 height=845 src=http://ep.yimg.com/33333333-2770333333333317019111></Picture>
<Orderable>YES</Orderable>
<Taxable>YES</Taxable>
<Pricing>
<BasePrice>178.00</BasePrice>
<LocalizedBasePrice>178.00</LocalizedBasePrice>
<OrigPrice>299.99</OrigPrice>
<LocalizedOrigPrice>299.99</LocalizedOrigPrice>
<SalePrice>178.00</SalePrice>
<LocalizedSalePrice>178.00</LocalizedSalePrice>
</Pricing>
<Path>
<ProductRef Id="wochsu" Url="http://www.cl333333333333hsu.html">Womens Church Suits</ProductRef>
<ProductRef Id="2454" Url="http://www.clo333333333nd.com/2454.html">Aussie Austine Spring/Summer 2011</ProductRef>
</Path>
<Availability>Usually ships the next business day.</Availability>
<Caption><head> <meta content="en-us" http-equiv="Content-Language"> <style type="text/css"> .style3 { font-family: arial, helvetica; font-size: medium; font-weight: bold; } .style4 { font-size: small; } </style> </head> <p><strong>Wholesale Women&#39;s Church Suits&nbsp; - 3 Piece Suit - Jacket/Vest/Long Skirt</strong></p> <p><strong>Aussie Austine Spring/Summer 2011</strong></p> <p class="style4"><strong>Wholesale Clothing Distributors - Church Attire, Gospel Fashion, Mother of Bride Style at a Wholesale Price. For all your fancy, classic, elegant parties and or occasions. Our suits come in a variety of styles to accommodate your fashion taste. Suits for all women, moms, grandma&#39;s, daughters and aunts. That classic look that will bring attention. From stylish skirts, pants, jackets and vests. Two piece suits, available hats and purses. Brand Name Wholesale Ladies Apparel. </strong></p> <p>3<strong> Piece Suit - Jacket/Vest/Long Skirt</strong></p> <p><strong>Sizes&nbsp; 8 10 12 14 16 18 20</strong></p> <p><strong>Color&nbsp; Khaki Red</strong></p> <p>Available Accessories: Hat and Purse&nbsp; </p> <font face="arial, helvetica" size="4"> <p align="left">Orders of 12 and 24 Items are Mixed Colors and Sizes. For more information Please call Us @ 323333300</p> <p align="left">Please feel free to call if you would like wholesale pricing for larger orders&nbsp;</font></p> <font face="arial, helvetica" size="2"> <p align="left"><b><font size="4">Please call or E-mail <a href="mailto:Sal333333sland.com">Sales@cloth333333333and.com</a> If you are interested in purchasing larger quantities</font></b></p> </font> <p align="left" class="style3">&nbsp;</p> <p align="left">&nbsp;</p> <p align="left">&nbsp;</p> <p align="left">`</p></Caption> 你可以在底部看到我提到的'Caption‘标签。
我以前从来没有使用过xslt,所以我目前只有一个框架,我只能基本上重复所有的数据,即使我使用‘匹配’模板,所有的文本都包含在最终的产品中。我知道我只是不正确地使用了模板,但我可以在任何地方找到这个概念的解释。我对match使用的措辞是:
<xsl:template match="Description"
<title>
<apply-template/>
</title>
</xsl:template> 目的是在最终的xml rss2.0文档中将'Description‘标记转换为'title’字段
编辑:
好的,我使用的是XSLTPalette,屏幕有3种输出模式:“原始”,“漂亮”,“渲染”结果。当我使用样式表从“标题”节点中剥离元素时,它们在“原始”结果中看起来就像我想要的那样,它只是没有转义字符的文本。在渲染结果中看起来也很好,但我的数据在渲染结果中仍然是非结构化的。它根本不会出现在“漂亮”的输出框中,但我猜“原始”越来越接近我的需求了。下面是一个示例的不完整样式表:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="//Product/Caption">
<xsl:param name="text"/>
<xsl:choose>
<xsl:when test="contains($text, '<')">
<xsl:value-of select="substring-before($text, '<')"/>
<xsl:call-template name="strip-tags">
<xsl:with-param name="text" select="substring-after($text, '>')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet> 两件事:这有效地剥离了节点的正确部分,但是我如何将这一部分的输出封装到最终文档的一个名为'description‘的标记中,以及我没有做什么事情来只在产品中显示我想要的东西,比如除了我指定的我想要的东西之外什么都不包含。
发布于 2011-02-12 13:26:00
如果看不到作为输入的确切内容,我只能建议您通过这个XSLT模板传递要从中剥离HTML的节点。
<xsl:template name="strip-tags">
<xsl:param name="text"/>
<xsl:choose>
<xsl:when test="contains($text, '<')">
<xsl:value-of select="substring-before($text, '<')"/>
<xsl:call-template name="strip-tags">
<xsl:with-param name="text" select="substring-after($text, '>')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>只需将其包含在现有的XSLT中,并将其应用于相关的<Caption>节点即可。
https://stackoverflow.com/questions/4976355
复制相似问题