parsing variable in value-of
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 3
- Joined: Thu Nov 02, 2006 4:37 pm
parsing variable in value-of
Hi,
I'm having problems trying to output the value of a variable. I've tried a LOT of different ways to solve it but i just seem to get back at this annoying problem.. It's hard to explain but imma give a try
This is the situation: i have a for-each loop over several xml-records. Each loop puts a string in a variable called $displayName. For each loop i want the script to return a value from the xml-document; the location of this value depends on the $displayName.
For instance, for a certain point in the loop the variable $displayName = 'companyName'. I want to call //HEADER/companyName, so i write <xsl:value-of select="//HEADER/$displayName"/> . XSL doesnt like it when i do that.
Is there a way to get around this? Thanks in advance!
I'm having problems trying to output the value of a variable. I've tried a LOT of different ways to solve it but i just seem to get back at this annoying problem.. It's hard to explain but imma give a try

This is the situation: i have a for-each loop over several xml-records. Each loop puts a string in a variable called $displayName. For each loop i want the script to return a value from the xml-document; the location of this value depends on the $displayName.
For instance, for a certain point in the loop the variable $displayName = 'companyName'. I want to call //HEADER/companyName, so i write <xsl:value-of select="//HEADER/$displayName"/> . XSL doesnt like it when i do that.
Is there a way to get around this? Thanks in advance!
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
-
- Posts: 3
- Joined: Thu Nov 02, 2006 4:37 pm
I'm sorry if im trying something really stupidgeorge wrote:<xsl:value-of select="//HEADER/*[name()=$displayName]"/>
Note that the above works when the input document is in no namespace. If your input is in one or more namespaces then you can check local-name instead of name and namespace-uri to check the namespace.
Best Regards,
George

The code i'm using is this:
Code: Select all
<xsl:choose>
<xsl:when test="//HEADER/*[name()=$displayName] != ''">
<xsl:value-of select="//HEADER/*[name()=$displayName]"/>
</xsl:when>
<xsl:otherwise>
pwn3d
</xsl:otherwise>
</xsl:choose>
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service