How to get XML node value in XSLT?

How to generate dynamic DIV id with XSLT?

  • Answer:

    Basically to insert the value of a node where a literal value would normally go you'll use the {} within the quoted string. I don't know what the xml you're wanting to pull the id from is so I'll give you two examples. 1) the id is in a node: source xml: <root><mydivid>divMine</mydivid></root... xslt: <div id="{//root/mydivid}"></div> 2) the id is in an attribute: source xml: <root mydivid="divMine"></root> xslt: <div id="{//root/@mydivid}"></div> Of course you can always declare an xsl:variable as well so that you don't have to use the whole xpath in the {}, or if you're in a template where the context is the parent node of the one that you're wanting to pull the id from you just use the name of the node or attribute in the {} (mydivid or @mydivid if your template's match="root"). Hopefully that's somewhat helpful!

bzkit1983 at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

Basically to insert the value of a node where a literal value would normally go you'll use the {} within the quoted string. I don't know what the xml you're wanting to pull the id from is so I'll give you two examples. 1) the id is in a node: source xml: <root><mydivid>divMine</mydivid></root… xslt: <div id="{//root/mydivid}"></div> 2) the id is in an attribute: source xml: <root mydivid="divMine"></root> xslt: <div id="{//root/@mydivid}"></div> Of course you can always declare an xsl:variable as well so that you don't have to use the whole xpath in the {}, or if you're in a template where the context is the parent node of the one that you're wanting to pull the id from you just use the name of the node or attribute in the {} (mydivid or @mydivid if your template's match="root"). Hopefully that's somewhat helpful!

LDonaghe

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.