Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xsl:value-of select=Expression

Status
Not open for further replies.

tnse

MIS
Apr 28, 2003
3
BE
Is it possible to make the expression variable and still to retrieve the content of a node?
example:
xml file1 need to be transformed to another xml file2.
file1 contains a repeating part (messagedetail)
<code>
<messagedetail>
<LITNOrder_qty_1>0</LITNOrder_qty_1>
<LITNOrder_qty_2>0</LITNOrder_qty_2>
</messagedetail>
...
</code>
file2 should be of the form:
<code>
<schedule>
<Qty Commit=&quot;4&quot; Freq=&quot;T&quot; New=&quot;0&quot; />
<Qty Commit=&quot;4&quot; Freq=&quot;T&quot; New=&quot;0&quot; />
</schedule>
...
</code>

The xsl file does this as followed:
<code>
<schedule>
<Qty Commit=&quot;4&quot; Freq=&quot;T&quot;>
<xsl:attribute name=&quot;New&quot;>
<xsl:value-of select=&quot;LITNOrder_qty_1&quot;/>
</xsl:attribute>
</schedule>
...
</code>

The value of the select expression is fixed, although it would be more interesting when it was variable. (in this case the qty number is from 1 to 12) I tried using the concat function and some looping resulting in following code
<code>
<xsl:call-template name=&quot;retrieve_schedule&quot;>
<xsl:with-param name=&quot;count&quot; select=&quot;1&quot;/>
</xsl:call-template>

<xsl:template name=&quot;retrieve_schedule&quot;>
<xsl:param name=&quot;count&quot;/>
<xsl:if test=&quot;$count &lt; 3&quot;>
<Qty Commit=&quot;4&quot; Freq=&quot;T&quot;>
<xsl:attribute name=&quot;New&quot;>
<xsl:value-of select=&quot;concat('LITNOrder_qty_',$count)&quot;/>
</xsl:attribute>
</Qty>
<xsl:call-template name=&quot;retrieve_schedule&quot;>
<xsl:with-param name=&quot;count&quot; select=&quot;$count + 1&quot;/>
</xsl:call-template>
<xsl:if
</xsl:template>
</code>

Unfortunately, the result was not the expected qty, but the name of the field.
<code>
<schedule>
<Qty Commit=&quot;4&quot; Freq=&quot;T&quot; New=&quot;LITNOrder_qty_1&quot; />
<Qty Commit=&quot;4&quot; Freq=&quot;T&quot; New=&quot;LITNOrder_qty_2&quot; />
</schedule>
...
</code>
Placing the concatination in a variable and calling this variable gives the same wrong result.

Any suggestions would be welcome
 
This is a part of the desired output:
<code>
<Line Number=&quot;1&quot;>
<ItemNumber Type=&quot;IN&quot;>14X-911-2150</ItemNumber>
<ItemNumber Type=&quot;SA&quot;>14X-911-2150</ItemNumber>
<ItemDescription>GLASS</ItemDescription>
<ItemUnix>PCE</ItemUnix>
<Schedule>
<Qty Commit=&quot;4&quot; Freq=&quot;T&quot; Week=&quot;20&quot; New=&quot;0&quot; />
<Qty Commit=&quot;4&quot; Freq=&quot;T&quot; Week=&quot;21&quot; New=&quot;1&quot; />
<Qty Commit=&quot;4&quot; Freq=&quot;T&quot; Week=&quot;22&quot; New=&quot;0&quot; />
<Qty Commit=&quot;4&quot; Freq=&quot;T&quot; Week=&quot;23&quot; New=&quot;5&quot; />
<Qty Commit=&quot;4&quot; Freq=&quot;T&quot; Week=&quot;24&quot; New=&quot;0&quot; />
</Schedule>
</Line>
<Line Number=&quot;2&quot;>
<ItemNumber Type=&quot;IN&quot;>14X-911-2210</ItemNumber>
<ItemNumber Type=&quot;SA&quot;>14X-911-2210</ItemNumber>
<ItemDescription>GLASS</ItemDescription>
<ItemUnix>PCE</ItemUnix>
<Schedule>
<Qty Commit=&quot;4&quot; Freq=&quot;T&quot; Week=&quot;20&quot; New=&quot;0&quot; />
<Qty Commit=&quot;4&quot; Freq=&quot;T&quot; Week=&quot;21&quot; New=&quot;0&quot; />
<Qty Commit=&quot;4&quot; Freq=&quot;T&quot; Week=&quot;22&quot; New=&quot;0&quot; />
<Qty Commit=&quot;4&quot; Freq=&quot;T&quot; Week=&quot;23&quot; New=&quot;1&quot; />
<Qty Commit=&quot;4&quot; Freq=&quot;T&quot; Week=&quot;24&quot; New=&quot;0&quot; />
</Schedule>
</Line>

...
</code>

The source xml-file is as followed build:
<code>
<messagedetail>
<LITIdentifier>R0055</LITIdentifier>
<LITItemDescription>GLASS</LITItemDescription>
<LITItemIdentifier>14X-911-2150</LITItemIdentifier>
<LITNOrder_qty_1>0</LITNOrder_qty_1>
<LITNPeriodValue_1>20</LITNPeriodValue_1>
<LITNOrder_qty_2>1</LITNOrder_qty_2>
<LITNPeriodValue_2>21</LITNPeriodValue_2>
<LITNOrder_qty_3>0</LITNOrder_qty_3>
<LITNPeriodValue_3>22</LITNPeriodValue_3>
<LITNOrder_qty_4>5</LITNOrder_qty_4>
<LITNPeriodValue_4>23</LITNPeriodValue_4>
<LITNOrder_qty_5>0</LITNOrder_qty_5>
<LITNPeriodValue_5>24</LITNPeriodValue_5>
</messagedetail>
<messagedetail>
<LITIdentifier>R0055</LITIdentifier>
<LITItemDescription>GLASS</LITItemDescription>
<LITItemIdentifier>14X-911-2221</LITItemIdentifier>
<LITNOrder_qty_1>0</LITNOrder_qty_1>
<LITNPeriodValue_1>20</LITNPeriodValue_1>
<LITNOrder_qty_2>0</LITNOrder_qty_2>
<LITNPeriodValue_2>21</LITNPeriodValue_2>
<LITNOrder_qty_3>0</LITNOrder_qty_3>
<LITNPeriodValue_3>22</LITNPeriodValue_3>
<LITNOrder_qty_4>1</LITNOrder_qty_4>
<LITNPeriodValue_4>23</LITNPeriodValue_4>
<LITNOrder_qty_5>0</LITNOrder_qty_5>
<LITNPeriodValue_5>24</LITNPeriodValue_5>
</messagedetail>
...
</code>

As mentioned before, I can do the job by repeating some part of the xsl file:
<code>
<schedule>
<Qty Commit=&quot;4&quot; Freq=&quot;T&quot;>
<xsl:attribute name=&quot;Week&quot;>
<xsl:value-of select=&quot;LITNPeriodValue_1&quot;/>
</xsl:attribute>
<xsl:attribute name=&quot;New&quot;>
<xsl:value-of select=&quot;LITNOrder_qty_1&quot;/>
</xsl:attribute>
<Qty Commit=&quot;4&quot; Freq=&quot;T&quot;>
<xsl:attribute name=&quot;Week&quot;>
<xsl:value-of select=&quot;LITNPeriodValue_2&quot;/>
</xsl:attribute>
<xsl:attribute name=&quot;New&quot;>
<xsl:value-of select=&quot;LITNOrder_qty_2&quot;/>
</xsl:attribute>
<Qty Commit=&quot;4&quot; Freq=&quot;T&quot;>
<xsl:attribute name=&quot;Week&quot;>
<xsl:value-of select=&quot;LITNPeriodValue_3&quot;/>
</xsl:attribute>
<xsl:attribute name=&quot;New&quot;>
<xsl:value-of select=&quot;LITNOrder_qty_3&quot;/>
...
</schedule>
...
</code>

, but it would be more interesting to have a more flexible way of doing this. In this specific case making the element name (eg &quot;LITNOrder_qty_1&quot;) variable by changing the number. I tried using the concat function for that, but instead of getting the value of the element, I only get the name of the element in my output.


I hope it is more clear to you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top