节点中的最后一项
我正在尝试查找节点中的最后一项,因此我可以指定是否指定逗号。
<?xml version="1.0" encoding="utf-16"?>
<?xml-stylesheet href="data.xsl" type="text/xsl"?>
<page generated="2011-04-19T19:22:21+00:00">
<realm generated="2011-04-19T14:36:41-04:00" name="H-Bloodhoof">
<item id="24033" name="Solid Star of Elune">
<market>230000</market>
<quantity>0</quantity>
<reagentprice>39204</reagentprice>
</item>
<item id="5976" name="Guild Tabard">
<market>60000</market>
<quantity>1</quantity>
<marketaverage>61162</marketaverage>
<marketstddev>19735</marketstddev>
<lastseen>2011-04-19T14:30:50-04:00</lastseen>
</item>
<item id="24036" name="Flashing Living Ruby">
<market>1100000</market>
<quantity>0</quantity>
<reagentprice>99617</reagentprice>
</item>
<item id="23108" name="Timeless Shadow Draenite">
<market>20000</market>
<quantity>0</quantity>
<marketaverage>20000</marketaverage>
<marketstddev>0</marketstddev>
<reagentprice>6500</reagentprice>
<lastseen>2011-04-15T00:46:15-04:00</lastseen>
</item>
</realm>
</page>
这是 xsl:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:template match="realm">
<xsl:apply-templates >
<xsl:with-param name="id" select="@id" />
</xsl:apply-templates>
</xsl:template>
<xsl:template match="item">
<xsl:param name="id" />
<xsl:text>addonTable.marketdata[</xsl:text><xsl:value-of select="@id" /><xsl:text>] = {</xsl:text>
<xsl:text>["market"] =</xsl:text><xsl:value-of select="market" />
<xsl:if test="not(following-sibling::*)"><xsl:text>,</xsl:text></xsl:if>
<xsl:text>["quantity"] =</xsl:text><xsl:value-of select="quantity" />
<xsl:if test="not(following-sibling::*)"><xsl:text>,</xsl:text></xsl:if>
<xsl:text>["marketaverage"] =</xsl:text><xsl:value-of select="marketaverage" />
<xsl:if test="not(following-sibling::*)"><xsl:text>,</xsl:text></xsl:if>
<xsl:text>["marketstddev"] =</xsl:text><xsl:value-of select="marketstddev" />
<xsl:if test="not(following-sibling::*)"><xsl:text>,</xsl:text></xsl:if>
<xsl:text>["reagentprice"] =</xsl:text><xsl:value-of select="reagentprice" />
<xsl:if test="not(following-sibling::*)"><xsl:text>,</xsl:text></xsl:if>
<xsl:text>["lastseen"] =</xsl:text><xsl:value-of select="lastseen" />
<xsl:if test="not(following-sibling::*)"><xsl:text>,</xsl:text></xsl:if>
<xsl:text>}</xsl:text>
</xsl:template>
</xsl:stylesheet>
所以现在它正在检查 Item 的最后一个同级元素,我希望它是该项目中的最后一个元素。
addonTable.marketdata[24033] = {["market"] =230000["quantity"] =0["marketaverage"] =["marketstddev"] =["reagentprice"] =39204["lastseen"] =}
addonTable.marketdata[5976] = {["market"] =60000["quantity"] =1["marketaverage"] =61162["marketstddev"] =19735["reagentprice"] =["lastseen"] =2011-04-19T14:30:50-04:00}
addonTable.marketdata[24036] = {["market"] =1100000["quantity"] =0["marketaverage"] =["marketstddev"] =["reagentprice"] =99617["lastseen"] =}
addonTable.marketdata[23108] = {["market"] =20000,["quantity"] =0,["marketaverage"] =20000,["marketstddev"] =0,["reagentprice"] =6500,["lastseen"] =2011-04-15T00:46:15-04:00,}
它应该看起来像这样,如果它不打印空值那就太好了。
addonTable.marketdata[24033] = {["market"] =230000,["quantity"] =0,["marketaverage"] =,["marketstddev"] =,["reagentprice"] =39204,["lastseen"] =}
addonTable.marketdata[5976] = {["market"] =60000,["quantity"] =1,["marketaverage"] =61162,["marketstddev"] =19735,["reagentprice"] =,["lastseen"] =2011-04-19T14:30:50-04:00}
addonTable.marketdata[24036] = {["market"] =1100000,["quantity"] =0,["marketaverage"] =,["marketstddev"] =,["reagentprice"] =99617,["lastseen"] =}
addonTable.marketdata[23108] = {["market"] =20000,["quantity"] =0,["marketaverage"] =20000,["marketstddev"] =0,["reagentprice"] =6500,["lastseen"] =2011-04-15T00:46:15-04:00}
感谢您的浏览!
I'm trying to find the last item in a node, so I can specify whether to specify a comma or not.
<?xml version="1.0" encoding="utf-16"?>
<?xml-stylesheet href="data.xsl" type="text/xsl"?>
<page generated="2011-04-19T19:22:21+00:00">
<realm generated="2011-04-19T14:36:41-04:00" name="H-Bloodhoof">
<item id="24033" name="Solid Star of Elune">
<market>230000</market>
<quantity>0</quantity>
<reagentprice>39204</reagentprice>
</item>
<item id="5976" name="Guild Tabard">
<market>60000</market>
<quantity>1</quantity>
<marketaverage>61162</marketaverage>
<marketstddev>19735</marketstddev>
<lastseen>2011-04-19T14:30:50-04:00</lastseen>
</item>
<item id="24036" name="Flashing Living Ruby">
<market>1100000</market>
<quantity>0</quantity>
<reagentprice>99617</reagentprice>
</item>
<item id="23108" name="Timeless Shadow Draenite">
<market>20000</market>
<quantity>0</quantity>
<marketaverage>20000</marketaverage>
<marketstddev>0</marketstddev>
<reagentprice>6500</reagentprice>
<lastseen>2011-04-15T00:46:15-04:00</lastseen>
</item>
</realm>
</page>
Here's xsl:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:template match="realm">
<xsl:apply-templates >
<xsl:with-param name="id" select="@id" />
</xsl:apply-templates>
</xsl:template>
<xsl:template match="item">
<xsl:param name="id" />
<xsl:text>addonTable.marketdata[</xsl:text><xsl:value-of select="@id" /><xsl:text>] = {</xsl:text>
<xsl:text>["market"] =</xsl:text><xsl:value-of select="market" />
<xsl:if test="not(following-sibling::*)"><xsl:text>,</xsl:text></xsl:if>
<xsl:text>["quantity"] =</xsl:text><xsl:value-of select="quantity" />
<xsl:if test="not(following-sibling::*)"><xsl:text>,</xsl:text></xsl:if>
<xsl:text>["marketaverage"] =</xsl:text><xsl:value-of select="marketaverage" />
<xsl:if test="not(following-sibling::*)"><xsl:text>,</xsl:text></xsl:if>
<xsl:text>["marketstddev"] =</xsl:text><xsl:value-of select="marketstddev" />
<xsl:if test="not(following-sibling::*)"><xsl:text>,</xsl:text></xsl:if>
<xsl:text>["reagentprice"] =</xsl:text><xsl:value-of select="reagentprice" />
<xsl:if test="not(following-sibling::*)"><xsl:text>,</xsl:text></xsl:if>
<xsl:text>["lastseen"] =</xsl:text><xsl:value-of select="lastseen" />
<xsl:if test="not(following-sibling::*)"><xsl:text>,</xsl:text></xsl:if>
<xsl:text>}</xsl:text>
</xsl:template>
</xsl:stylesheet>
So right now it's checking for the last sibling of Item where I would like it do be the last element within the item.
addonTable.marketdata[24033] = {["market"] =230000["quantity"] =0["marketaverage"] =["marketstddev"] =["reagentprice"] =39204["lastseen"] =}
addonTable.marketdata[5976] = {["market"] =60000["quantity"] =1["marketaverage"] =61162["marketstddev"] =19735["reagentprice"] =["lastseen"] =2011-04-19T14:30:50-04:00}
addonTable.marketdata[24036] = {["market"] =1100000["quantity"] =0["marketaverage"] =["marketstddev"] =["reagentprice"] =99617["lastseen"] =}
addonTable.marketdata[23108] = {["market"] =20000,["quantity"] =0,["marketaverage"] =20000,["marketstddev"] =0,["reagentprice"] =6500,["lastseen"] =2011-04-15T00:46:15-04:00,}
It should look like this and it would be great if it doesn't print the empty values.
addonTable.marketdata[24033] = {["market"] =230000,["quantity"] =0,["marketaverage"] =,["marketstddev"] =,["reagentprice"] =39204,["lastseen"] =}
addonTable.marketdata[5976] = {["market"] =60000,["quantity"] =1,["marketaverage"] =61162,["marketstddev"] =19735,["reagentprice"] =,["lastseen"] =2011-04-19T14:30:50-04:00}
addonTable.marketdata[24036] = {["market"] =1100000,["quantity"] =0,["marketaverage"] =,["marketstddev"] =,["reagentprice"] =99617,["lastseen"] =}
addonTable.marketdata[23108] = {["market"] =20000,["quantity"] =0,["marketaverage"] =20000,["marketstddev"] =0,["reagentprice"] =6500,["lastseen"] =2011-04-15T00:46:15-04:00}
Thanks for looking!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
此样式表:
输出:
addonTable.marketdata[24033] = {["market"] = 230000,["quantity"] = 0,["reagentprice"] = 39204}
addonTable.marketdata[5976] = {["market"] = 60000,["quantity"] = 1,["marketaverage"] = 61162,["marketstddev"] = 19735,["lastseen"] = 2011 -04-19T14:30:50-04:00}
addonTable.marketdata[24036] = {["市场"] = 1100000,["数量"] = 0,["试剂价格"] = 99617}
addonTable.marketdata[23108] = {["市场"] = 20000,["数量"] = 0,["市场平均"] = 20000,["市场stddev"] = 0,["试剂价格"] = 6500 ,["lastseen"] = 2011-04-15T00:46:15-04:00}
This stylesheet:
Output:
addonTable.marketdata[24033] = {["market"] = 230000,["quantity"] = 0,["reagentprice"] = 39204}
addonTable.marketdata[5976] = {["market"] = 60000,["quantity"] = 1,["marketaverage"] = 61162,["marketstddev"] = 19735,["lastseen"] = 2011-04-19T14:30:50-04:00}
addonTable.marketdata[24036] = {["market"] = 1100000,["quantity"] = 0,["reagentprice"] = 99617}
addonTable.marketdata[23108] = {["market"] = 20000,["quantity"] = 0,["marketaverage"] = 20000,["marketstddev"] = 0,["reagentprice"] = 6500,["lastseen"] = 2011-04-15T00:46:15-04:00}
我会为 market|quantity|etc 创建一个模板,并将逗号检查移到 tha 中,它也会简化您当前正在做的事情。
I'd create a template for market|quantity|etc and move teh comma check into tha, it will also simplify what your are currently doing.