好吧,我有一个xslt样式表,它可以完成我现在需要的大部分工作,看起来是这样的:
<?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/Description">
<title>
<xsl:apply-templates/>
</title>
</xsl:template>
<xsl:template match="//Product/Picture">
<link>
<xsl:apply-templates/>
</link>
</xsl:template>
<xsl:template match="//Product/Caption">
<description>
<xsl:apply-templates/>
</description>
</xsl:template>
<xsl:template match="Picture">
<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, src= )"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="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:apply-templates/>
</xsl:template>
</xsl:stylesheet>
这可能是一个巨大的错误,因为我只是从xml编辑器的原始输出中获取文本,因为它可以满足我的需要。它把正确的标签放在正确的地方。然而,现在strip标签似乎不起作用了,我尝试制作另一个版本的strip标签,它将剥离src=之后和>;之前的所有内容;但很明显,脱衣舞标签与我想做的相反。有什么东西与脱衣舞标签相反吗?然后我可以把strip-tag这个词替换为strip-all except或其他名称
EDIT:
here is the input xml file:
<?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>Cl33333</StoreName>
<Currency>USD</Currency>
<ShipMethods>
<ShipMethod></ShipMethod>
</ShipMethods>
<PayMethods>
</PayMethods>
</Settings>
<Products>
<Product Id="agfasu">
<Code>3616a</Code>
<Description>Ageless Fashion Suit</Description>
<Url>http://www.cl333333333d.com/agfasu.html</Url>
<Thumb><img border=0 width=50 height=70 src=http://ep.y3333333333327706119506618_2144_317652924></Thumb>
<Picture><img border=0 width=600 height=845 src=http://ep.yim3333333st-27706119506618_2144_317019111></Picture>
<Orderable>YES</Orderable>
<Taxable>YES</Taxable>
<Pricing>
<BasePrice>178.00</BasePrice>
</Pricing>
<Path>333333333333333om/wochsu.html">Womens Church Suits</ProductRef>
<ProductRef Id="2454" Url="http://www.cl33333333454.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</Caption>
<OptionLists>
<OptionList name="Size">
<OptionValue>8</OptionValue>
</OptionList>
<OptionList name="Colors">
<OptionValue>Red</OptionValue>
</OptionList>
<OptionList name="Accessories">
<OptionValue>Suit</OptionValue>
</OptionList>
</OptionLists>
</Product>
我想要的输出:
<item>
<title>
<![CDATA[ DescriptionTag]]>
</title>
<description>
<![CDATA[CaptionTagStrippedofEscapedCharacters]]>
</description>
<link> UrlTag </link>
<g:condition>new</g:condition>
<g:price> BasePriceTag </g:price>
<g:product_type>Clothing, Accessories</g:product_type>
<g:image_link> PictureTagFrom src= to > </g:image_link>
<g:payment_accepted>Visa</g:payment_accepted>
<g:payment_accepted>Mastercard</g:payment_accepted>
<g:payment_accepted>Discover</g:payment_accepted>
</item>
有些标签不需要从来源填充,但总是相同的,例如接受付款、条件和产品类型