[thelist] Using php to transform xml

David Miller dmiller at mcc.ca
Fri May 25 13:14:55 CDT 2012


There's more than one way to do it, of course, but what you're looking for is the <xsl:attribute> element. Here's an example:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
        <xsl:template match="plan">
                <h1>Planner</h1>
                <xsl:apply-templates select="task"/>
        </xsl:template>
        <xsl:template match="task">
                <div>
                        <xsl:attribute name="class"><xsl:value-of select="status"/></xsl:attribute>
                        <span class='title'><xsl:value-of select="title"/></span>
                        <span class='description'><xsl:value-of select="description"/></span>
                        <span class='notes'><xsl:value-of select="notes"/></span>
                </div>
        </xsl:template>
</xsl:stylesheet>

======================================================================
David R. Miller
Manager, Software Development / Gestionnaire, Élaboration de logiciels
Information Technology / Services informatiques
MEDICAL COUNCIL OF CANADA / LE CONSEIL MÉDICAL DU CANADA
Tel. / Tél. : (613) 521-6012 ext. / poste 2265
Fax / Téléc. : (613) 521-9417
Email / Courriel : dmiller at mcc.ca
www.mcc.ca

>Hi there
>
>I know I should probably do a proper course on xml and xslt but I just need
>a really quick solution for this small job - then I can probe further.
>
>I have an xml file with nested tasks:
>
><plan>
><task>
>  <title>Walk</title>
>  <status>prop</status>
>  <description>Learn to walk</description>
>  <notes>Gaining strength and balance</notes>
></task>
>
>I want to output xhtml so that each task has a container with a class
>equivalent to its 'status', eg. <div
>class='prop'><title/><description/><notes/></div>
>
>This is a snippet of my xsl file:
>
><h1>Planner</h1>
><xsl:for-each select="plan/task">
><div>
><span><xsl:value-of select="status" /></span>
><span class='title'><xsl:value-of select="title" /></span>
><span class='description'><xsl:value-of select="description" /></span>
><span class='notes'><xsl:value-of select="notes" /></span>
></div>
></xsl:for-each>
>
>I don't want a 'status' span, I want it to be the class of the div.
>
>Does this make sense and is there a relatively simple solution?
>
>Thanks
>
>Chris.Price
>@Choctaw.co.uk <http:\\choctaw.co.uk>
>0777 629 0227



This email may contain privileged and/or confidential information, and the Medical Council of Canada does not waive any related rights. Any distribution, use, copying or disclosure of this email or the information it contains by other than the intended recipient is strictly prohibited. If you received this email in error please delete it immediately from your system and notify the sender promptly by email that you have done so. The integrity and security of this message cannot be guaranteed on the Internet.  If you prefer not to receive MCC communications by e-mail, please send us an e-mail with only “unsubscribe” in the subject line to unsubscribe at mcc.ca.  Any questions about our privacy practices should be made in writing and directed to the Privacy Committee at 2283 St. Laurent Blvd., Ottawa ON K1G 3H7.

Le présent courriel peut contenir de l'information privilégiée ou confidentielle. Le Conseil médical du Canada ne renonce pas aux droits qui s'y rapportent. Toute diffusion, utilisation ou copie de ce courriel ou des renseignements qu'il contient par une personne autre que le ou les destinataires désignés est interdite. Si vous recevez ce courriel par erreur, veuillez le supprimer immédiatement et envoyer sans délai à l'expéditeur un message électronique pour l'aviser que vous avez éliminé de votre ordinateur toute copie du courriel reçu. L'intégrité et la sécurité de ce message ne peuvent pas être garanties sur l'Internet.  Si vous ne voulez pas que le CMC communique avec vous par courriel, vous pouvez nous faire parvenir un courriel à l’adresse suivante unsubscribe at mcc.ca et inscrire dans la ligne d’objet « désabonnement ».   Si vous avez des questions ou des préoccupations concernant notre politique sur la protection des renseignements personnels, n'hésitez pas à en faire part par écrit au comité de protection des renseignements personnels, au 2283, boul. St-Laurent, Ottawa (Ontario) K1G 3H7.


More information about the thelist mailing list