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!

Get the value of an attribute 1

Status
Not open for further replies.

Gaelle

Programmer
Jun 20, 2001
62
FR
Hello !

I have a XML file like this :
<par><title id=&quot;456&quot;>This Title has for id 456</title>
<bodypar>some text</bodypar></par>
and other titles with others ids.

In my XSL file, I want to make something like :
<xsl:for-each select=&quot;par&quot;>
<input type=&quot;text&quot;>
<xsl:attribute name=&quot;value&quot;>
<xsl:value-of select=&quot;titre&quot;/>
</xsl:attribute>
<xsl:attribute name=&quot;name&quot;>
titre<xsl:value-of select=&quot;titre.[@id]&quot;/>
</xsl:attribute>
</input><br/>
...
to finaly get somthing like :
<input type=&quot;text&quot; value=&quot;This Title has for id 456&quot; name=&quot;titre456&quot;>

What can I put instead of titre<xsl:value-of select=&quot;titre.[@id]&quot;/> to have it working ?

Thank you,
Gaelle.

 
Hello,
It seems that you did a typo - in your xml file the tag is title, not titre.
Also [] are used for condition.
Try this xsl and with View/source check the results:
<xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot; <xsl:template match=&quot;/&quot;>
<html>
<body>
<form action=&quot;aaa.asp&quot;>
<xsl:for-each select=&quot;/doc/par&quot;>
<input type=&quot;text&quot;>
<xsl:attribute name=&quot;value&quot;><xsl:value-of select=&quot;title/text()&quot;/></xsl:attribute>
<xsl:attribute name=&quot;name&quot;>titre<xsl:value-of select=&quot;title/@id&quot;/></xsl:attribute>
</input>
<br/>
</xsl:for-each>
</form>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
 
Hello,

I can't have it working.
I can set any attribute I want for my input tag like size for example, but I can't set the attribute name, it still gives nothing in return.
If I put the name attribute in the input tag with any value, it works, but I can't give the value with an XSL:value-of tag.

The problem now is : how not to do what I had expected to ?
Thank you for your help,
Gaelle.
 
Hello,
Did you try
<xsl:attribute name=&quot;name&quot;>titre</xsl:attribute>
If that works as expected try
<xsl:attribute name=&quot;name&quot;>titre<xsl:value-of select=&quot;title&quot;/></xsl:attribute>
I guess that may be you are not accessing the right path.
In my example I used for-each clause that selected the right node in the tree.
Then again try
<xsl:attribute name=&quot;name&quot;>titre<xsl:value-of select=&quot;title/@id&quot;/></xsl:attribute>

Hope this helps.
D.
 
Hello,
I forgot to remind you that name of input button will be visible only from View/Source.
D.
 
Hello !

...And thank you for helping me !
in fact, even
<xsl:attribute name=&quot;name&quot;>titre</xsl:attribute>
doesn't work
And I'm sure it could work because :
<xsl:for-each select=&quot;par&quot;>
<input type=&quot;text&quot;>
<xsl:attribute name=&quot;size&quot;><xsl:value-of select=&quot;title/@id&quot;/></xsl:attribute>
</input>...
perfectly works, and gives an input field, which size is equal to the id of my title !
Maybe I am not allowed to put <xsl:attribute name=&quot;name&quot;>...

Thank you anyway for helping me !
Gaelle.


 
Well,
You are allowed, since you do not get any error.
Name attribute is visible only in the resulting code.
You have to choose from browser menu to View Source in order to see the name.
Success!
D.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top