30 likes | 135 Vues
Using XSLT and XPath to Transform XML Documents into Text Files. Roger L. Costello XML Technologies. Problem. Create a stylesheet that creates a text file containing each member's data. Line for each member Member data separated by a slash delimiter. Jeff/555-1234/555-4321/lightgrey
E N D
Using XSLT and XPath to Transform XML Documents into Text Files Roger L. Costello XML Technologies
Problem • Create a stylesheet that creates a text file containing each member's data. • Line for each member • Member data separated by a slash delimiter Jeff/555-1234/555-4321/lightgrey David/383-1234/383-4321/lightblue Roger/888-1234/888-4321/lightyellow
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="text"/> <xsl:variable name="delimiter" select="'/'"/> <xsl:template match="FitnessCenter"> <xsl:for-each select="Member"> <xsl:apply-templates select="."/> <xsl:text>
</xsl:text> <!-- Hex value for carriage return --> </xsl:for-each> </xsl:template> <xsl:template match="Member"> <xsl:for-each select="*[position() < last()]"> <xsl:value-of select="."/> <xsl:value-of select="$delimiter"/> </xsl:for-each> <xsl:value-of select="*[last()]"/> </xsl:template> </xsl:stylesheet> (see text-example01)