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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

<xsl:for-each

Status
Not open for further replies.

castali

Programmer
Jan 26, 2004
24
DE
I have the folowing XML file >>>

<page>
<item langue=&quot;fr&quot;>
<javascripts defaut=&quot;1&quot;>
<javascript>js_one</javascript>
<javascript>js_two</javascript>
</javascripts>
<stylesheets defaut=&quot;1&quot;>
<stylesheet media=&quot;all&quot; title=&quot;&quot;>st_one</stylesheet>
<stylesheet media=&quot;print&quot; title=&quot;oui&quot;>st_two</stylesheet>
</stylesheets>
</item>
</page>
-----------------------------------------
connected to this XSLT file >>>

<xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot; <xsl:eek:utput method=&quot;xml&quot; version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot; indent=&quot;yes&quot;/>
<xsl:template match=&quot;/&quot;>
<xsl:for-each select=&quot;//page/item[@langue='fr']/javascripts&quot;>
<xsl:if test=&quot;@defaut='1'&quot;>
<script src=&quot;javascript/default.js&quot; type=&quot;text/javascript&quot;/>
</xsl:if>
<script src=&quot;javascript/{javascript}.js&quot; type=&quot;text/javascript&quot;/>
</xsl:for-each>
<xsl:for-each select=&quot;//page/item[@langue='fr']/stylesheets&quot;>
<xsl:if test=&quot;@defaut='1'&quot;>
<link href=&quot;stylesheet/default.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; media=&quot;all&quot;/>
<link href=&quot;stylesheet/formulaires.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; media=&quot;all&quot;/>
</xsl:if>
<link href=&quot;stylesheet/{stylesheet}.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; media=&quot;{@media}&quot; title=&quot;{@title}&quot;/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

---------------------

and I get only >>>>

js_one


do you know why ?

thank you
 
It's because you are looping over &quot;javascripts&quot; and the following statement gets the first &quot;javascript&quot;.

<script src=&quot;javascript/{javascript}.js&quot; type=&quot;text/javascript&quot;/>

You need to loop like this:

<xsl:for-each select=&quot;/page/item[@langue='fr']/javascripts/javascript&quot;>

Your XSLT will be much easier to write if your XML was restructured. Here is an example:

<page>
<item xml:lang=&quot;fr&quot;>
<javascript defaut=&quot;1&quot;>js_one</javascript>
<javascript defaut=&quot;1&quot;>js_two</javascript>
<stylesheet defaut=&quot;1&quot; media=&quot;all&quot; title=&quot;&quot;>st_one</stylesheet>
<stylesheet defaut=&quot;1&quot; media=&quot;print&quot; title=&quot;oui&quot;>st_two</stylesheet>
</item>
</page>

<xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot; <xsl:eek:utput method=&quot;xml&quot; version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot; indent=&quot;yes&quot;/>
<xsl:template match=&quot;/&quot;>
<xsl:apply-templates/>
</xsl:template>

<xsl:template match=&quot;page&quot;>
<xsl:for-each select=&quot;item[lang('fr')]&quot;>
<xsl:if test=&quot;javascript[defaut='1']&quot;>
<script src=&quot;javascript/default.js&quot; type=&quot;text/javascript&quot;/>
</xsl:if>
<xsl:for-each select=&quot;javascript&quot;>
<script src=&quot;javascript/{text()}.js&quot; type=&quot;text/javascript&quot;/>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
 
oh I didn't knew you can us

<script src=&quot;javascript/{text()}.js&quot; type=&quot;text/javascript&quot;/>

with {text()}

thanks a ton for all !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top