[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: XML Elements Tag (lable) Name is assign at run tim
amit.parikh wrote: > i have tested 2nd solution. > i got error on this line > <xsl:key name="equiv" match="../element" use="element"/> Sorry, I meant match="element" use="../element" I also made an error in the named template. Here's an example that I tested. The stylesheet looks for 'DOB' but because DOB is in the mapping file as being equivalent to DateOfBirth, data can be obtained from the DateOfBirth element in the source tree. customer.xml ============= <Customer> <Name>Amit</Name> <DateOfBirth>01/01/1970</DateOfBirth> <ZipCode>12121</ZipCode> </Customer> equivelem.xml ============= <sourceMappings> <equivalentElementNames> <element>DOB</element> <element>DateOfBirth</element> </equivalentElementNames> <equivalentElementNames> <element>ZipCode</element> <element>PostCode</element> </equivalentElementNames> </sourceMappings> test.xsl ============= <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="no"/> <xsl:key name="equiv" match="element" use="../element"/> <xsl:variable name="mappings" select="document('equivelem.xml')/sourceMappings"/> <xsl:template match="Customer"> <result> <xsl:call-template name="get-childElem-stringValue"> <xsl:with-param name="childElem-name" select="'DOB'"/> </xsl:call-template> </result> </xsl:template> <xsl:template name="get-childElem-stringValue"> <xsl:param name="childElem-name"/> <xsl:variable name="currentNode" select="."/> <xsl:for-each select="$mappings"> <xsl:variable name="elements" select="key('equiv',$childElem-name)"/> <xsl:value-of select="$currentNode/*[local-name()=$elements]"/> </xsl:for-each> </xsl:template> </xsl:stylesheet> result of applying test.xsl to customer.xml with Saxon 6.5.2: ============================================================= <?xml version="1.0" encoding="utf-8"?><result>01/01/1970</result> Mike -- Mike J. Brown | http://skew.org/~mike/resume/ Denver, CO, USA | http://skew.org/xml/ 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
|