[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
RE: Multi-Line Elements
Subject: RE: Multi-Line Elements From: Mike Brown <mbrown@xxxxxxxxxxxxx> Date: Mon, 23 Aug 1999 17:44:13 -0600 |
> <billing_address>123 Any Pl. > Suite 5 > Thisplace, AB > 12345 > Attn: John</billing_address> > > that needs to parsed into individual lines during output. <!-- The better solution, as pointed out previously, would be to adjust your DTD such that the meaningful units of data exist as separate elements. But if you insist... --> <!-- If your XSLT processor implements the right functions, and if you don't mind doing this as many times as you expect to see newline characters in the input, you can do it like this. Or, you could make this into a named template that accepts a line number on input and then recursively calls itself that many times to return the result. --> <!-- put the text into a variable so it is easier to work with --> <xsl:variable name="All" select="billing_address"/> <!-- $Line_1 = what comes before first newline --> <xsl:variable name="Line_1" select="substring-before($All,'
')"/> <!-- $The_Rest = what comes after first newline --> <xsl:variable name="The_Rest" select="substring-after($All,'
')"/> <!-- $Line_2 = what comes before first newline in $The_Rest, or just $The_Rest if there is no newline --> <xsl:variable name="Line_2"> <xsl:choose> <xsl:when test="contains($The_Rest,'
')"> <xsl:value-of select="substring-before($The_Rest,'
')"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="$The_Rest"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <!-- reassign $The_Rest safely --> <xsl:variable name="TEMP_The_Rest" select="substring-after($The_Rest,'
')"/> <xsl:variable name="The_Rest" select="$TEMP_The_Rest"/> <!-- do subsequent lines just like $Line_2 --> <xsl:variable name="Line_3"> <xsl:choose> <xsl:when test="contains($The_Rest,'
')"> <xsl:value-of select="substring-before($The_Rest,'
')"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="$The_Rest"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:variable name="TEMP_The_Rest" select="substring-after($The_Rest,'
')"/> <xsl:variable name="The_Rest" select="$TEMP_The_Rest"/> <xsl:variable name="Line_4"> <xsl:choose> <xsl:when test="contains($The_Rest,'
')"> <xsl:value-of select="substring-before($The_Rest,'
')"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="$The_Rest"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:variable name="TEMP_The_Rest" select="substring-after($The_Rest,'
')"/> <xsl:variable name="The_Rest" select="$TEMP_The_Rest"/> <xsl:variable name="Line_5"> <xsl:choose> <xsl:when test="contains($The_Rest,'
')"> <xsl:value-of select="substring-before($The_Rest,'
')"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="$The_Rest"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:variable name="TEMP_The_Rest" select="substring-after($The_Rest,'
')"/> <xsl:variable name="The_Rest" select="$TEMP_The_Rest"/> <xsl:variable name="Line_6"> <xsl:choose> <xsl:when test="contains($The_Rest,'
')"> <xsl:value-of select="substring-before($The_Rest,'
')"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="$The_Rest"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:variable name="TEMP_The_Rest" select="substring-after($The_Rest,'
')"/> <xsl:variable name="The_Rest" select="$TEMP_The_Rest"/> <!-- and so on. --> <!-- If there aren't enough newlines in the input, you'll start getting empty strings, but that should be all right; you can test for them. --> <!-- display each line in curly braces --> <xsl:text>{</xsl:text> <xsl:value-of select="$Line_1"/> <xsl:text>}</xsl:text> <xsl:text>{</xsl:text> <xsl:value-of select="$Line_2"/> <xsl:text>}</xsl:text> <xsl:text>{</xsl:text> <xsl:value-of select="$Line_3"/> <xsl:text>}</xsl:text> <xsl:text>{</xsl:text> <xsl:value-of select="$Line_4"/> <xsl:text>}</xsl:text> <xsl:text>{</xsl:text> <xsl:value-of select="$Line_5"/> <xsl:text>}</xsl:text> <xsl:text>{</xsl:text> <xsl:value-of select="$Line_6"/> <xsl:text>}</xsl:text> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: Multi-Line Elements, Alex Shevchuk | Thread | XSL + Gecko, Joerg Brunsmann |
ANNOUNCE: XSLT Newline to <br> Demo, Mike Brown | Date | Re: key and document(), James Clark |
Month |
Keywords