[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Design question
Wanted: >BEFORE: > <test type="positive" name="Test 1"> > <param name="p1">123</param> > <param name="date1">July 9</param> > <param name="p2">false</param> > </test> > >AFTER: > <da:Positive name="Test 1" p1="123" p2="false"> > <da:Date number="1" value="July 9"/> > </da:Positive> > I tested this and it works. As I see it, the weakness in my approach is that I'm making assumptions in how your param elements may vary. (I.e. I hard-coded 'date' in one template, and make the assumption that the names won't vary.) It was tested using MSXML 4. It seems to me that you could easily build templates for each name pattern and extend this to be more robust. I'm just learning, so these little exercises are helpful! --Jeff <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl='http://www.w3.org/1999/XSL/Transform' > <xsl:output method="xml" indent="yes"/> <xsl:template match="/"> <xsl:apply-templates select="test"/> </xsl:template> <xsl:template match="test"> <xsl:element name="{@type}"> <xsl:copy-of select="@name"/> <xsl:apply-templates select="param[contains(@name,'p')]"/> <xsl:apply-templates select="param[contains(@name,'date')]"/> </xsl:element> </xsl:template> <xsl:template match="param[contains(@name,'p')]"> <xsl:attribute name="{@name}"> <xsl:value-of select="."/> </xsl:attribute> </xsl:template> <xsl:template match="param[contains(@name,'date')]"> <xsl:element name="Date"> <xsl:attribute name="number"> <xsl:value-of select="translate(@name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz','')"/> </xsl:attribute> <xsl:attribute name="value"> <xsl:value-of select="."/> </xsl:attribute> </xsl:element> </xsl:template> </xsl:stylesheet> 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
|