Skip to content

Instantly share code, notes, and snippets.

@weberjn
Created August 7, 2023 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weberjn/276bf8405852bd5408c8c03394b97e3f to your computer and use it in GitHub Desktop.
Save weberjn/276bf8405852bd5408c8c03394b97e3f to your computer and use it in GitHub Desktop.
Google contacts phone numbers to MicroSIP Contacts.xml

Google Contacts To MicroSIP Contacts.xml

export phone book to Google CSV

convert to xml with Notepad++ Plugin CSV Lint

Table name / XML Root : contact

save as c.xml

XSLT transform xml to MicroSIP Contacts.xml

xsltproc -o Contacts.xml contacts.xsl c.xml
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
	<xsl:strip-space elements="*"/>
	<xsl:template match="/">
		<contacts>
			<xsl:for-each select="xml/contact">
				<contact>
					<xsl:attribute name="name">
						<xsl:value-of select="Name"/>
					</xsl:attribute>
					
					<xsl:if test="(Phone_1_Type = 'Home')">
							<xsl:attribute name="number">
								<xsl:value-of select="Phone_1_Value"/>
							</xsl:attribute>
					</xsl:if>

					<xsl:if test="(Phone_1_Type = 'Mobile')">
							<xsl:attribute name="mobile">
								<xsl:value-of select="Phone_1_Value"/>
							</xsl:attribute>
					</xsl:if>


					<xsl:if test="(Phone_2_Type = 'Home')">
							<xsl:attribute name="number">
								<xsl:value-of select="Phone_2_Value"/>
							</xsl:attribute>
					</xsl:if>

					<xsl:if test="(Phone_2_Type = 'Mobile')">
							<xsl:attribute name="mobile">
								<xsl:value-of select="Phone_2_Value"/>
							</xsl:attribute>
					</xsl:if>
					

					<xsl:if test="(Phone_3_Type = 'Home')">
							<xsl:attribute name="number">
								<xsl:value-of select="Phone_3_Value"/>
							</xsl:attribute>
					</xsl:if>

					<xsl:if test="(Phone_3_Type = 'Mobile')">
							<xsl:attribute name="mobile">
								<xsl:value-of select="Phone_3_Value"/>
							</xsl:attribute>
					</xsl:if>
															
				</contact>
			</xsl:for-each>
		</contacts>
	</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment