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

XSLT problem

Status
Not open for further replies.

satellite03

IS-IT--Management
Dec 26, 2003
248
IN
XML
===
<source>

<employee id="js0034"> Joe Smith </employee>

</source>






XSLT
======
<xsl:stylesheet version = '1.0'
xmlns:xsl='<xsl:template match="employee">
<xsl:value-of select="."/>
<xsl:text>[</xsl:text>
<xsl:apply-templates select="@id"/>
<xsl:text>]</xsl:text>
</xsl:template>

<xsl:template match="@id">
<b>
<i>
<xsl:value-of select="."/> --> line 1
</i>
</b>
</xsl:template>

</xsl:stylesheet>


output:
======

Joe Smith
[<b>
<i>js0034</i>
</b>]


question
===========

Look at line 1

<xsl:value-of select tag always gives the value of the element . here the element is the <employee . and its values is "Joe Smith" . so the output should have been "Joe Smith" but i am getting the output as "js0034". why it is like this ?
 
satellite03 said:
<xsl:value-of select tag always gives the value of the element
This is true, but you are not using <xsl:value-of select tag. In line 1 you are using <xsl:value-of select="."/>, which will output the value of the current context. In this case the context is @id, therefore the value is 'js0034'.

Jon

"Asteroids do not concern me, Admiral. I want that ship, not excuses.
 
thank for the reply.

i am getting difficulty to percept fully. i understand your point but there are some trouble i am facing.


let me explain where is my trouble


i thought, when the processor will see this statement

<xsl:template match="@id">

It w'll think [blue] "Ok , i have got an element whose attibute is 'id' ". and that is only available in the '<employee element. so my current context is the '<employee element.[/blue]


now the processor will come down and come across

<xsl:value-of select="."/> --> line 1

so, this time , it will think [blue]"As my current context is '<element' so i will get the value of the root(because "." means root of the context). so i will output "Joe Smith".[/blue]


whats wrong in this approach ?
 
please answer my above question.


i believe context means element . is it wrong ?
 
Context can be a node or attribute

Jon

"Asteroids do not concern me, Admiral. I want that ship, not excuses.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top