[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Transforming text into a variable name
At 99/10/20 11:16 -0700, Scott Sanders wrote:
Is there a way in XSLT to transform a attribute text value to a variable name. No, but you can use an attribute's value to find a variable's declaration in the stylesheet, which may work for what you are looking for. For Example: A working example is below. If your variables are not result tree fragments, you'll have to do some awkward string manipulation since string values are specified inside of quotes. I hope this helps. ......... Ken T:\sanders>type sanders.xml <?xml version="1.0"?> <test> <search title="Search for record" var="test1"/> <search title="Search for another" var="test2"/> </test> T:\sanders>type sanders.xsl <?xml version="1.0"?> <!DOCTYPE xsl:stylesheet [<!ENTITY nl "
">]> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:variable name="test1">Value of first variable</xsl:variable> <xsl:variable name="test2">Value of second variable</xsl:variable> <xsl:template match="/"> <result> <xsl:apply-templates/> </result> </xsl:template> <xsl:template match="search"> <!--go to the stylesheet file and find the top-level variable declaration whose name attribute is equal to the current node's var attribute--> <xsl:value-of select="@title"/>: '<xsl:value-of select="document('')/*/xsl:variable[@name=current()/@var]"/>' </xsl:template> </xsl:stylesheet> T:\sanders>xt sanders.xml sanders.xsl <result> Search for record: 'Value of first variable' Search for another: 'Value of second variable' </result> T:\sanders>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|