我对带有标记属性的正确测试变量有问题 [英] I have problems with right test variable with mark attribute
问题描述
你好,我想测试变量,如果可能的话,我想要它带有属性.所以我有一个 XML:
<td class="column-country">美属萨摩亚 <span class="type">(手机)</span></td><td class="column-rate">0.500</td><td class="column-vat">0.575</td></tr><tr class=""><td class="column-country">安道尔 <span class="type">(固定电话)</span><span class="free">FREE*</span><span class="superdeal">SuperDeal!**</span></td><td class="column-rate">免费*</td><td class="column-vat">免费*</td></tr>当 td class = "column-rate" 为 FREE* 时,我需要输入数字 0,否则为正常速率.如果可能,我希望它具有属性/免费 = 1,费率 = 0.或免费 = 0,费率 = 0.500.或者以正常方式 :D... 没有免费...所以如果列包含来自 FREE*,则输入数字 0.END.
我试试这个:
<国家/地区><xsl:variable name="country" select="normalize-space(xhtml:td[@class='column-country'])"/><xsl:attribute name="name"><xsl:value-of select="normalize-space(substring-before($country, '('))"/></xsl:attribute><费率><xsl:variable name="type1" select="normalize-space(xhtml:td[@class = 'column-country']/xhtml:span)"/><xsl:variable name="type" select="translate($type1, '()', '') "/><xsl:variable name="price" select="normalize-space(translate(xhtml:td[@class = 'column-rate'], 'abcdefghijklmnopqrstuvwzyxABCDEFGHIJKLMNOPQRSTUVVWXYZ()*¢$€', ''))"/><xsl:variable name="cena"><xsl:when test="$price != ''"><xsl:value-of select="$price"/><xsl:apply-templates select="."/></xsl:when><xsl:否则><xsl:value-of select="$VAT"/></xsl:否则></xsl:选择></xsl:变量><xsl:variable name="cena1" select="normalize-space(substring-before($cena, '(')) "/><xsl:variable name="cena2" select="normalize-space(translate(xhtml:td[@class = 'column-rate'], 'abcdefghijklmnopqrstuvwzyxABCDEFGHIJKLMNOPQRSTUVVWXYZ()*¢$€', ''))"/><xsl:attribute name="type"><xsl:value-of select="$type"/></xsl:attribute><xsl:attribute name="operator"></xsl:attribute><xsl:attribute name="货币"><xsl:value-of select="$Currency"/></xsl:attribute><xsl:attribute name="vat"><xsl:value-of select="$VAT"/></xsl:attribute><xsl:attribute name="unit"><xsl:value-of select="$UNIT"/></xsl:attribute><xsl:value-of select="$cena2"/></率></国家>
我的输出是:
<国家名称="美属萨摩亚"><rate type="Mobile" operator=""currency="EUR"vat="0" unit="minute">0.500</rate></国家><国家名称="安道尔"><rate type="Landline" operator=""currency="EUR"vat="0" unit="minute"/></国家>
但我需要:
<国家名称="美属萨摩亚"><rate type="Mobile" operator=""currency="EUR"vat="0" unit="minute">0.500</rate></国家><国家名称="安道尔"><rate type="Landline" operator=""currency="EUR"vat="0" unit="minute"/>0</rate></国家>
或
<国家名称="美属萨摩亚"><rate type="Mobile" operator=""currency="EUR"vat="0" unit="minute">0.500</rate></国家><国家名称="安道尔"><rate type="Landline" operator=""currency="EUR"vat="0" unit="minute" free="1"/>0</rate></国家>
但它不能正常工作,因为当它免费时,费率是空的.
解决方案 怎么样:
<预><代码>...<xsl:variable name="cena"><xsl:when test="number($price)"><xsl:value-of select="$price"/></xsl:when><xsl:否则><xsl:value-of select="0"/></xsl:否则></xsl:选择></xsl:变量>...Hello I want to test variable, if its possible, I want it with attribute. So I have a XML:
<tr class="alt-row">
<td class="column-country">American Samoa <span class="type">(Mobile)</span></td>
<td class="column-rate">0.500</td>
<td class="column-vat">0.575</td>
</tr>
<tr class="">
<td class="column-country">Andorra <span class="type">(Landline)</span> <span class="free">FREE*</span> <span class="superdeal">SuperDeal!**</span></td>
<td class="column-rate">FREE*</td>
<td class="column-vat">FREE*</td>
</tr>
And when td class = "column-rate" is FREE*, I need to put number 0, otherwise its normal rate. If its possible I want it with attribute / free = 1, rate = 0. or free = 0, rate = 0.500. Or in normal way :D... without free... So if column contains from FREE*, put number 0. END.
I try this:
<country>
<xsl:variable name="country" select="normalize-space(xhtml:td[@class='column-country'])"/>
<xsl:attribute name="name">
<xsl:value-of select="normalize-space(substring-before($country, '('))"/>
</xsl:attribute>
<rate>
<xsl:variable name="type1" select="normalize-space(xhtml:td[@class = 'column-country']/xhtml:span)"/>
<xsl:variable name="type" select="translate($type1, '()', '') "/>
<xsl:variable name="price" select="normalize-space(translate(xhtml:td[@class = 'column-rate'], 'abcdefghijklmnopqrstuvwzyxABCDEFGHIJKLMNOPQRSTUVVWXYZ()*¢$€', '')) "/>
<xsl:variable name="cena">
<xsl:choose>
<xsl:when test="$price != ''">
<xsl:value-of select="$price"/>
<xsl:apply-templates select="."/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$VAT"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="cena1" select="normalize-space(substring-before($cena, '(')) "/>
<xsl:variable name="cena2" select="normalize-space(translate(xhtml:td[@class = 'column-rate'], 'abcdefghijklmnopqrstuvwzyxABCDEFGHIJKLMNOPQRSTUVVWXYZ()*¢$€', '')) "/>
<xsl:attribute name="type">
<xsl:value-of select="$type"/>
</xsl:attribute>
<xsl:attribute name="operator">
</xsl:attribute>
<xsl:attribute name="currency">
<xsl:value-of select="$Currency"/>
</xsl:attribute>
<xsl:attribute name="vat">
<xsl:value-of select="$VAT"/>
</xsl:attribute>
<xsl:attribute name="unit">
<xsl:value-of select="$UNIT"/>
</xsl:attribute>
<xsl:value-of select="$cena2"/>
</rate>
</country>
and my ouput is:
<country name="American Samoa">
<rate type="Mobile" operator="" currency="EUR" vat="0" unit="minute">0.500</rate>
</country>
<country name="Andorra">
<rate type="Landline" operator="" currency="EUR" vat="0" unit="minute"/>
</country>
but i need that:
<country name="American Samoa">
<rate type="Mobile" operator="" currency="EUR" vat="0" unit="minute">0.500</rate>
</country>
<country name="Andorra">
<rate type="Landline" operator="" currency="EUR" vat="0" unit="minute"/>0</rate>
</country>
or
<country name="American Samoa">
<rate type="Mobile" operator="" currency="EUR" vat="0" unit="minute">0.500</rate>
</country>
<country name="Andorra">
<rate type="Landline" operator="" currency="EUR" vat="0" unit="minute" free="1"/>0</rate>
</country>
But its not work correctly, because when its FREE, the rate is empty.
解决方案 How about:
...
<xsl:variable name="cena">
<xsl:choose>
<xsl:when test="number($price)">
<xsl:value-of select="$price"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="0"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
...
这篇关于我对带有标记属性的正确测试变量有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文
登录
关闭
扫码关注1秒登录
发送“验证码”获取
|
15天全站免登陆