Я пытаюсь найти последний элемент в узле, чтобы я мог указать, указывать ли запятую или нет.
<?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}
Спасибо за внимание!