Subject: Re: [xsl] vcf to xml? From: "Eliot Kimber eliot.kimber@xxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Fri, 24 Jun 2022 15:55:16 -0000 |
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<https://www.servicenow.com> LinkedIn<https://www.linkedin.com/company/servicenow> | Twitter<https://twitter.com/servicenow> | YouTube<https://www.youtube.com/user/servicenowinc> | Facebook<https://www.facebook.com/servicenow> 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.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] vcf to xml?, C. M. Sperberg-McQue | Thread | Re: [xsl] vcf to xml?, Dave Pawson dave.paw |
Re: [xsl] vcf to xml?, Pieter Masereeuw pie | Date | Re: [xsl] vcf to xml?, Dave Pawson dave.paw |
Month |