Subject: Re: [xsl] vcf to xml? From: "Dave Pawson dave.pawson@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Fri, 24 Jun 2022 16:38:37 -0000 |
Thanks Eliot. (To be investigated!) regards On Fri, 24 Jun 2022 at 16:55, Eliot Kimber eliot.kimber@xxxxxxxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > > This transform: > > <?xml version="1.0" encoding="UTF-8"?> > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > xmlns:xs="http://www.w3.org/2001/XMLSchema" > exclude-result-prefixes="xs" > version="3.0" > expand-text="yes" > > > > <xsl:output indent="yes"/> > > <!-- The URI of the vcf data to read --> > <xsl:param name="vcf-uri" as="xs:string"/> > > <xsl:template name="run"> > <xsl:variable name="vcf-data" as="xs:string?" select="unparsed-text($vcf-uri)"/> > <xsl:if test="empty($vcf-data)"> > <xsl:message terminate="yes">- [ERROR] Failed to read VFC data at "{$vcf-uri}"</xsl:message> > </xsl:if> > <xsl:message>+ [DEBUG] vcf data: > <xsl:sequence select="$vcf-data"/> > </xsl:message> > > <xsl:variable name="vcf-lines" as="xs:string+" > select="$vcf-data ! tokenize(., '\n')" > /> > <vcf> > <xsl:apply-templates select="$vcf-data[1]"> > <xsl:with-param name="lines" as="xs:string*" tunnel="yes" select="tail($vcf-lines)"/> > </xsl:apply-templates> > </vcf> > </xsl:template> > > <xsl:template match=".[starts-with(., 'BEGIN:VCARD')]" priority="10"> > <xsl:param name="lines" as="xs:string*" tunnel="yes"/> > <vcard> > <xsl:apply-templates select="$lines"/> > </vcard> > </xsl:template> > > <xsl:template match=".[starts-with(., 'END:VCARD')]" priority="10"> > <!-- Ignore --> > </xsl:template> > > <xsl:template match=".[matches(., '\w+:.+')]"> > <xsl:analyze-string select="." regex="(\w+):(.+)"> > <xsl:matching-substring> > <xsl:element name="{regex-group(1)}"> > <xsl:choose> > <xsl:when test="contains(regex-group(2), ';')"> > <xsl:analyze-string select="regex-group(2)" regex="([^;]*);"> > <xsl:matching-substring> > <line>{regex-group(1)}</line> > </xsl:matching-substring> > <xsl:non-matching-substring> > <line>{.}</line> > </xsl:non-matching-substring> > </xsl:analyze-string> > </xsl:when> > <xsl:otherwise>{regex-group(2)}</xsl:otherwise> > </xsl:choose> > </xsl:element> > </xsl:matching-substring> > </xsl:analyze-string> > </xsl:template> > > </xsl:stylesheet> > > > > Given this input: > > > > BEGIN:VCARD > VERSION:3.0 > N:Lastname;Surname > FN:Displayname > ORG:EVenX > URL:http://www.evenx.com/ > EMAIL:info@xxxxxxxxx > TEL;TYPE=voice,work,pref:+49 1234 56788 > ADR;TYPE=intl,work,postal,parcel:;;Wallstr. 1;Berlin;;12345;Germany > END:VCARD > > > > Produces this result: > > > > <?xml version="1.0" encoding="UTF-8"?> > <vcf> > <vcard> > <VERSION>3.0</VERSION> > <N> > <line>Lastname</line> > <line>Surname</line> > </N> > <FN>Displayname</FN> > <ORG>EVenX</ORG> > <URL>http://www.evenx.com/</URL> > <EMAIL>info@xxxxxxxxx</EMAIL> > <pref>+49 1234 56788</pref> > <parcel> > <line/> > <line/> > <line>Wallstr. 1</line> > <line>Berlin</line> > <line/> > <line>12345</line> > <line>Germany</line> > </parcel> > </vcard> > </vcf> > > > > Cheers, > > > > E. > > > > _____________________________________________ > > Eliot Kimber > > Sr Staff Content Engineer > > O: 512 554 9368 > > M: 512 554 9368 > > servicenow.com > > LinkedIn | Twitter | YouTube | Facebook > > > > From: Dave Pawson dave.pawson@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> > Date: Friday, June 24, 2022 at 7:18 AM > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> > Subject: [xsl] vcf to xml? > > [External Email] > > > Anyone aware of a stylesheet for this conversion please, > Sure it's been written somewhere? > > TiA > > -- > Dave Pawson > XSLT XSL-FO FAQ. > Docbook FAQ. > > XSL-List info and archive > EasyUnsubscribe (by email) -- Dave Pawson XSLT XSL-FO FAQ. Docbook FAQ.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] vcf to xml?, Eliot Kimber eliot.k | Thread | [xsl] Expand XPath with a few abstr, Roger L Costello cos |
Re: [xsl] vcf to xml?, Eliot Kimber eliot.k | Date | Re: [xsl] vcf to xml?, BR Chrisman brchrism |
Month |