我想創建一個具有RSS 2.0的基本要素的數據饋送,看起來像這樣:XSLT樣式表對XML和去格式化HTML
<?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>
的標記。這個'Caption'字段格式化爲html,我想將Caption數據拖入'description'中,只是將其顯示爲文本並刪除所有的html標籤。在樣式表中它看起來像什麼?
編輯:
傳入的XML文件看起來像這樣(只包括一個「項目」元素):
<?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">[email protected]</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>
,你可以看到「標題」標籤,在我的底部所提及。
我從來沒有使用過xslt,所以我目前只有一個骨架,我只能基本上重複所有的數據,即使我使用'匹配'模板,所有文本都包含在最終產品中。我知道我只是錯誤地使用了模板,但我可以在任何地方找到這個概念。我使用匹配的寫法是:
<xsl:template match="Description"
<title>
<apply-template/>
</title>
</xsl:template>
與轉向「說明」標籤爲「標題」字段中的最後XML RSS2.0文件的意圖
編輯:
好,我使用XSLTPalette,屏幕有3種輸出模式:'原始','漂亮','渲染'結果。當我使用樣式表時,我現在已經去掉了'Caption'節點中的元素,它們看起來像我想要的'原始'結果,它只是沒有所有轉義字符的文本。在呈現的結果中也顯示得很好,但是我的數據在渲染結果中仍然是非結構化的。它不會出現在'漂亮'的輸出框中,但'生'越來越接近我所需要的,我猜。這裏是一個例子一個不完整的樣式表:
<?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>
兩件事情:這有效地去掉節點的正確部分,但如何將我也概括了本節的輸出到一個名爲「說明」的最後文件標籤,以及我沒有做的只有我想要的東西出現在產品中,就像除了我指定的我想要的東西之外什麼也沒有包含。
顯示傳入的XML示例和當前使用的XSLT,謝謝。 – ocodo 2011-02-12 05:23:07
您能否提供真正的XML文檔?現在「