tia_kamakshi
asked on
Updating variable value in loop in xslt
Hi,
For first article , I was creating url variable
<xsl:variable name="url" select="concat($base, $pathIs)"/>
which depends on other 2 variables as below:
<xsl:variable name="firstNews" select="article[1]" />
<xsl:variable name="pathIs" select="$firstNews/@xml">< /xsl:varia ble>
Now, I have article variable in loop. I understand the variable value once assigned cannot be changed in XSLT
Therefore, I need to setup value for variable firstNews as per article pasition.
Something like this:
<xsl:variable name="firstNews" select="article[position() ]" />
Please can you advise that below code is correct. If not please help me correcting.
I cannot test it before tomorrow morning.
Please advise.
Regards,
For first article , I was creating url variable
<xsl:variable name="url" select="concat($base, $pathIs)"/>
which depends on other 2 variables as below:
<xsl:variable name="firstNews" select="article[1]" />
<xsl:variable name="pathIs" select="$firstNews/@xml"><
Now, I have article variable in loop. I understand the variable value once assigned cannot be changed in XSLT
Therefore, I need to setup value for variable firstNews as per article pasition.
Something like this:
<xsl:variable name="firstNews" select="article[position()
Please can you advise that below code is correct. If not please help me correcting.
I cannot test it before tomorrow morning.
<xsl:for-each select="article[position() > 1 and position() < 3]">
<xsl:variable name="firstNews" select="article[position()]" />
<xsl:variable name="pathIs" select="$firstNews/@xml"></xsl:variable>
<xsl:variable name="url" select="concat($base, $pathIs)"/>
<img width="246" height="175" class="latest-news-item-thumb">
<xsl:attribute name="src">
<xsl:value-of select="concat($imgPath, '/', document($url)//image[@type='S']/src)"/>
</xsl:attribute>
</img>
</xsl:for-each>
I am working on ASP.net2.0 using C#Please advise.
Regards,
ASKER
Hi Gertone,
Thanks for your reply
I have variable called $base where it has the value where image resides for all the articles
My below xslt is reading summary xml something like this
From this detail xml I wanted to fetch the image name having [@type='S']/src
So, from the below code basically I wanted to fetch the image path:
<xsl:attribute name="src">
<xsl:value-of select="concat($imgPath, '/', document($url)//image[@typ e='S']/src )"/>
</xsl:attribute>
Please advise
Thanks for your reply
I have variable called $base where it has the value where image resides for all the articles
My below xslt is reading summary xml something like this
<?xml version="1.0" encoding="utf-16"?>
<newsindex>
<article id="944714" xml="Website\xslt\ReadingAnotherXmlWithinXSLT\944714.xml" date="20120802134700" image="Phuket-tn_tcm133-944615.jpg" publish="20120802134700">
<title>News 1</title>
<summary>Lorem1 ipsum dolor sit amet.</summary>
</article>
<article id="944130" xml="Website\xslt\ReadingAnotherXmlWithinXSLT\9447145.xml" date="20120802134700" image="Phuket-tn_tcm133-944634.jpg" publish="20130802134700">
<title>News 2</title>
<summary>Lorem2 ipsum dolor sit amet.</summary>
</article>
</newsindex>
In the xml attribute above, I have the path of detail xml where all the details can be seen. From this detail xml I wanted to fetch the image name having [@type='S']/src
So, from the below code basically I wanted to fetch the image path:
<xsl:attribute name="src">
<xsl:value-of select="concat($imgPath, '/', document($url)//image[@typ
</xsl:attribute>
<xsl:for-each select="article[position() > 1 and position() < 3]">
<xsl:variable name="firstNews" select="article[position()]" />
<xsl:variable name="pathIs" select="$firstNews/@xml"></xsl:variable>
<xsl:variable name="url" select="concat($base, $pathIs)"/>
<img width="246" height="175" class="latest-news-item-thumb">
<xsl:attribute name="src">
<xsl:value-of select="concat($imgPath, '/', document($url)//image[@type='S']/src)"/>
</xsl:attribute>
</img>
</xsl:for-each>
Please advise
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Many Many Thanks
welcome
<xsl:for-each select="article[position()
<xsl:variable name="firstNews" select="article[position()
inside the for each the context is the article
so the variable should rather be like this
<xsl:variable name="firstNews" select="." />
but I don't see you using the variable inside the for-each.
Notice that a variable does not live outside its scope (in this case the variable $firstNews can only be used inside the for-each)