From 1a775d7119de2af3bc3931befa08d19f8b050075 Mon Sep 17 00:00:00 2001 From: Neil Williams Date: Thu, 9 Mar 2006 16:54:44 +0000 Subject: [PATCH] Optional XSL stylesheets and support - prototypes git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13566 57a11ea4-9604-0410-9ed3-97b8803252fd --- ChangeLog | 17 + configure.in | 1 + src/optional/Makefile.am | 2 +- src/optional/xsl/Makefile.am | 13 + src/optional/xsl/README | 98 ++ src/optional/xsl/date-time.xsl | 1447 +++++++++++++++++ .../xsl/gnucash-gnccustomer-vcard2.xsl | 74 + src/optional/xsl/gnucash-std.xsl | 140 ++ src/optional/xsl/string.xsl | 1233 ++++++++++++++ src/optional/xsl/vcard-gnccustomer.pl | 103 ++ 10 files changed, 3127 insertions(+), 1 deletion(-) create mode 100644 src/optional/xsl/Makefile.am create mode 100644 src/optional/xsl/README create mode 100644 src/optional/xsl/date-time.xsl create mode 100644 src/optional/xsl/gnucash-gnccustomer-vcard2.xsl create mode 100644 src/optional/xsl/gnucash-std.xsl create mode 100644 src/optional/xsl/string.xsl create mode 100755 src/optional/xsl/vcard-gnccustomer.pl diff --git a/ChangeLog b/ChangeLog index 6d85564f81..f06c205d40 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2006-03-09 Neil Williams + * src/optional/xsl : New directory for optional XSL + * src/optional/xsl/vcard-gnccustomer.pl : Perl script + to create QSF from VCards + * src/optional/xsl/gnucash-gnccustomer-vcard2.xsl : + XSL to generate vcards from QSF (gncCustomer) + * src/optional/xsl/gnucash-std.xsl : Common routines + for gnucash XSL stylesheets + * src/optional/xsl/Makefile.am : Don't build, just install. + * src/optional/xsl/string.xsl : xsltsl standard library XSL + in place until available as a package. + * src/optional/xsl/README : Notes on using XSL and examples. + * src/optional/xsl/date-time.xsl : xsltsl standard library. + * src/optional/Makefile.am : install only. + * configure.in : Add instruction to build a Makefile in + src/optional/xsl + 2006-03-09 Neil Williams * src/business/business-core/gncInvoice.c : Enable diff --git a/configure.in b/configure.in index fef80a4461..bd8881a65d 100644 --- a/configure.in +++ b/configure.in @@ -2228,6 +2228,7 @@ AC_CONFIG_FILES(po/Makefile.in src/optional/Makefile src/optional/swig/Makefile src/optional/swig/examples/Makefile + src/optional/xsl/Makefile src/pixmaps/Makefile src/quotes/Makefile src/register/Makefile diff --git a/src/optional/Makefile.am b/src/optional/Makefile.am index c8e394b973..1d70384929 100644 --- a/src/optional/Makefile.am +++ b/src/optional/Makefile.am @@ -6,4 +6,4 @@ # get this to work (automake 1.4p5). SUBDIRS = -DIST_SUBDIRS = swig +DIST_SUBDIRS = swig xsl diff --git a/src/optional/xsl/Makefile.am b/src/optional/xsl/Makefile.am new file mode 100644 index 0000000000..9365599514 --- /dev/null +++ b/src/optional/xsl/Makefile.am @@ -0,0 +1,13 @@ +xsldir = ${datadir}/xml/gnucash/xsl + +xsl_DATA = \ + README \ + date-time.xsl \ + gnucash-std.xsl \ + string.xsl \ + gnucash-gnccustomer-vcard2.xsl \ + vcard-gnccustomer.pl + +EXTRA_DIST = \ + ${xsl_DATA} + diff --git a/src/optional/xsl/README b/src/optional/xsl/README new file mode 100644 index 0000000000..9d25aa04ae --- /dev/null +++ b/src/optional/xsl/README @@ -0,0 +1,98 @@ +GnuCash, XSL and QSF. +==================== + + If you need to convert gnucash QSF data into other formats, take a look at the example + stylesheets installed with gnucash. You are welcome to contribute new or amended + stylesheets - just post them on the QOF-devel mailing list. + + http://lists.sourceforge.net/lists/listinfo/qof-devel + + Depending on your package manager, the XSL stylesheets should be installed in + /usr/share/xml/gnucash/xsl/, or on Fink /sw/share/xml/gnucash/xsl/. + + Current stylesheets are works in progress, but include: + + · gnucash-gnccustomer-vcard2.xsl + + This stylesheet converts QSF export gnucash customer data into a brief Vcard, + suitable for upload to Kaddressbook. Each VCard is written into a separate .vcf + file, named after the contact described in the pilot_address records. Spaces are + replaced with underscores. Specify the '-o dir/' option to xsltproc to output all + vcards into a directory. + + · Others + + Stylesheets for ICS, vcal and possibly LDAP are planned. Any plain text, XML or HTML + format can be generated, theoretically. If you have a request for an XSL stylesheet + or if you have a stylesheet you would like to make available to others, mention it + on the QOF-devel mailing list. + + Also included is a perl script: + + · vcard-gnccustomer.pl + + The script uses the Text::vCard::Addressbook CPAN module to parse VCard files, + including those from other applications, into QSF XML that could be imported into + gnucash and merged into your gnucash customer list. With a few tweaks, this could + also be configured to create QSF XML suitable for gnucash vendor or employee records. + + You are free to copy and modify these stylesheets to your own requirements, including + translations and customised formats. Depending on your package manager, this is often + best done by copying the installed file to a local directory before modifying it. + GnuCash does not reference these stylesheets directly. If your modifications could be + useful to others, please contribute them to gnucash via the QOF-devel mailing list or + gnucash-devel mailing list. Submitted stylesheets should be licenced under the GNU GPL. + + +LOCALISATION (l10N) OF STYLESHEET OUTPUT. +======================================== + + Later HTML stylesheets will support providing translatable strings and user-specific + encodings via external parameters. This can make the command line very long so is best + performed using a script. Each descriptive word in the output is configured as a string + parameter for the stylesheet and can be replaced with a translated version. HTML output + supports setting the HTML language (as would be specified in the lang attribute) + and the encoding (as would be specified in the charset value in the content + attribute). If you use these stylesheets via a scripting language - like bash, PHP or + Perl - you could automate the translation by passing values obtained from a normal get- + text PO file. Copy the translatable strings into your script file as normal variables + then mark up those variables for translation by gettext. When the script is called, get- + text will assign the translated values to the variables and your script can simply echo + those values to the calls to the XSL parser routines. + + It is important that the HTML language and the encoding match each other AND the + expected content of the HTML output generated from the gnucash QSF data. + + When providing translated strings, the same constraints apply as if you were using get- + text and a normal PO file: the context and format of the translation should match the + intention expressed in the default value of the parameter. If the default is plural, the + translation should be plural. If the default is capitalised, the translation should be + capitalised - subject to grammatical rules for that language - even if the parameter + name itself is not capitalised. + + Each stylesheet specifies the translatable strings in a block near the top of the file, + marked as for the attention of translators. Common settings, like the HTML language + parameter and the encoding support, are in the gnucash-std.xsl stylesheet and are + available in all HTML stylesheets by using the string parameters html_lang and encoding. + + For more information, please ask on the gnucash-devel mailing list, the QOF-devel mailing + list or see the pilot-qof source: http://pilot-qof.sourceforge.net/ + +EXAMPLES +======== + + Convert a QSF XML file containing gncCustomer records, into individual VCard .vcf files + in the vcards/ directory - which must already exist. Files are named according to either + the company or name of the gncAddress record. + + $ xsltproc -o vcards/ gnucash-gnccustomer-vcard2.xsl addresses.xml + + This example is based on an "in-progress" QSF invoice stylesheet for gnucash that is based + on the existing pilot-qof HTML invoice stylesheet. It overrides the default mileage-rate + (0.30 currency units per unit distance) and the default hourly-rate (20 currency units per + hour) provided by the stylesheet with user specific values. The example is here just to + indicate how --stringparam would be used. + + $ xsltproc --stringparam mileage-rate 0.45 --stringparam hourly-rate 21 -o invoices/ + pilot-qof-invoice-xhtml.xsl invoice.xml + diff --git a/src/optional/xsl/date-time.xsl b/src/optional/xsl/date-time.xsl new file mode 100644 index 0000000000..7616b650ff --- /dev/null +++ b/src/optional/xsl/date-time.xsl @@ -0,0 +1,1447 @@ + + + + + + + $Id: date-time.xsl,v 1.1.2.1 2006/02/28 08:47:05 neil Exp $ + + + Diamond + Jason + + + 2004 + Steve Ball + + + 2001 + Jason Diamond + + + + Date/Time Processing + + +
+ Introduction + + This module provides templates for formatting and parsing date/time strings. + + See http://www.tondering.dk/claus/calendar.html for more information on calendars and the calculations this library performs. + +
+
+ +
+ + + Returns a string with a formatted date/time. + + + The formatted date/time is determined by the format parameter. The default format is %Y-%m-%dT%H:%M:%S%z, the W3C format. + + + + + + + xsd-date-time + + The date-time value in XML Schemas (WXS) format. + If this value is specified, it takes priority over other parameters. + + + + + year + + Year + + + + + month + + Month (1 - 12; January = 1) + + + + + day + + Day of month (1 - 31) + + + + + hour + + Hours since midnight (0 - 23) + + + + + minute + + Minutes after hour (0 - 59) + + + + + second + + Seconds after minute (0 - 59) + + + + + time-zone + + Time zone string (e.g., 'Z' or '-08:00') + + + + + format + + The format specification. + + + + %a + + Abbreviated weekday name + + + + + %A + + Full weekday name + + + + + %b + + Abbreviated month name + + + + + %B + + Full month name + + + + + %c + + Date and time representation appropriate for locale + + + + + %d + + Day of month as decimal number (01 - 31) + + + + + %e + + Day of month as decimal number (1 - 31) + + + + + %H + + Hour in 24-hour format (00 - 23) + + + + + %I + + Hour in 12-hour format (01 - 12) + + + + + %i + + Hour in 12-hour format (1 - 12) + + + + + %j + + Day of year as decimal number (001 - 366) + + + + + %m + + Month as decimal number (01 - 12) + + + + + %n + + Month as decimal number (1 - 12) + + + + + %M + + Minute as decimal number (00 - 59) + + + + + %P + + Current locale's A.M./P.M. indicator for 12-hour clock, uppercase + + + + + %Q + + Current locale's A.M./P.M. indicator for 12-hour clock, uppercase with periods + + + + + %p + + Current locale's A.M./P.M. indicator for 12-hour clock, lowercase + + + + + %q + + Current locale's A.M./P.M. indicator for 12-hour clock, lowercase with periods + + + + + %S + + Second as decimal number (00 - 59) + + + + + %U + + Week of year as decimal number, with Sunday as first day of week (00 - 53) + + + + + %w + + Weekday as decimal number (0 - 6; Sunday is 0) + + + + + %W + + Week of year as decimal number, with Monday as first day of week (00 - 53) + + + + + %x + + Date representation for current locale + + + + + %X + + Time representation for current locale + + + + + %y + + Year without century, as decimal number (00 - 99) + + + + + %Y + + Year with century, as decimal number + + + + + %z + + Time-zone name or abbreviation; no characters if time zone is unknown + + + + + %% + + Percent sign + + + + + + + + + + + + Returns a formatted date/time string. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + % + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [not implemented] + + + + + 0 + + + + + + + + + + 0 + + + + + + + 12 + 0 + + 0 + + + + + + + 12 + + + + + + + + + + [not implemented] + + + + + 0 + + + + + + + + + + 0 + + + + + + + am + pm + + + + + + am + p.m. + + + + + + AM + PM + + + + + + AM + P.M. + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [not implemented] + + + + + [not implemented] + + + + + [not implemented] + + + + + + + + + + + + + + + % + + + + + + + + + + + + + + + + + + + + + + + Calculates the day of the week. + + + Given any Gregorian date, this calculates the day of the week. + + + + + + year + + Year + + + + month + + Month (1 - 12; January = 1) + + + + day + + Day of month (1 - 31) + + + + + + + Returns the day of the week (0 - 6; Sunday = 0). + + + + + + + + + + + + + + + + + + + Calculates the number of days for a specified month. + + + Given any Gregorian month, this calculates the last day of the month. + + + + + + year + + Year + + + + month + + Month (1 - 12; January = 1) + + + + + + + Returns the number of days in given month as a decimal number. + + + + + + + + + + + 29 + 28 + + + + + 30 + 31 + + + + + 30 + 31 + + + + + + + Gets the day of the week's full name. + + + Converts a numeric day of the week value into a string representing the day's full name. + + + + + + day-of-the-week + + Day of the week (0 - 6; Sunday = 0) + + + + + + + Returns a string. + + + + + + + + + Sunday + Monday + Tuesday + Wednesday + Thursday + Friday + Saturday + error: + + + + + + Gets the day of the week's abbreviation. + + + Converts a numeric day of the week value into a string representing the day's abbreviation. + + + + + + day-of-the-week + + Day of the week (0 - 6; Sunday = 0) + + + + + + + Returns a string. + + + + + + + + + Sun + Mon + Tue + Wed + Thu + Fri + Sat + error: + + + + + + Gets the month's full name. + + + Converts a numeric month value into a string representing the month's full name. + + + + + + month + + Month (1 - 12; Januaray = 1) + + + + + + + Returns a string. + + + + + + + + + January + February + March + April + May + June + July + August + September + October + November + December + error: + + + + + + Gets the month's abbreviation. + + + Converts a numeric month value into a string representing the month's abbreviation. + + + + + + month + + Month (1 - 12; Januaray = 1) + + + + + + + Returns a string. + + + + + + + + + Jan + Feb + Mar + Apr + May + Jun + Jul + Aug + Sep + Oct + Nov + Dec + error: + + + + + + Calculates the Julian Day for a specified date. + + + Given any Gregorian date, this calculates the Julian Day. + + + + + + year + + Year + + + + month + + Month (1 - 12; January = 1) + + + + day + + Day of month (1 - 31) + + + + + + + Returns the Julian Day as a decimal number. + + + + + + + + + + + + + + + + + + + Returns a string with a formatted date for a specified Julian Day. + + + Given any Julian Day, this returns a string according to the format specification. + + + + + + julian-day + + A Julian Day + + + + format + + The format specification. See dt:format-date-time for more details. + + + + + + + A string. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Calculates the week number for a specified date. + + + Assumes Monday is the first day of the week. + + + + + + year + + Year + + + + month + + Month (1 - 12; January = 1) + + + + day + + Day of month (1 - 31) + + + + + + + Returns the week number as a decimal number. + + + + + + + + + + + + + + + + + + + + + + + + + + + Take a month by name and return a number which can be used as input to the templates. + + + Input + + + + + + month + + Month as described either by full name or abbreviation. + + + + + + + Return a month as a decimal number. (Jan = 1) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Return year component of XSD DateTime value. + + + Extract component of XML Schemas DateTime value. + + + + + + xsd-date-time + + A value in XSD DateTime format. + + + + + + + Returns year component. + + + + + + + + + + + + + + + + + + + + + + + + + Return month component of XSD DateTime value. + + + Extract component of XML Schemas DateTime value. + + + + + + xsd-date-time + + A value in XSD DateTime format. + + + + + + + Returns month component. + + + + + + + + + + + + + + + + + + + + + + + + + Return day component of XSD DateTime value. + + + Extract component of XML Schemas DateTime value. + + + + + + xsd-date-time + + A value in XSD DateTime format. + + + + + + + Returns day component. + + + + + + + + + + + + + + + + + + + + + + + + + Return hour component of XSD DateTime value. + + + Extract component of XML Schemas DateTime value. + + + + + + xsd-date-time + + A value in XSD DateTime format. + + + + + + + Returns hour component. + + + + + + + + + + + + + + + + + + + + + + + + + + Return minute component of XSD DateTime value. + + + Extract component of XML Schemas DateTime value. + + + + + + xsd-date-time + + A value in XSD DateTime format. + + + + + + + Returns minute component. + + + + + + + + + + + + + + + + + + + + + + + + + + Return second component of XSD DateTime value. + + + Extract component of XML Schemas DateTime value. + + + + + + xsd-date-time + + A value in XSD DateTime format. + + + + + + + Returns second component. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Return timezone component of XSD DateTime value. + + + Extract component of XML Schemas DateTime value. + + + + + + xsd-date-time + + A value in XSD DateTime format. + + + + + + + Returns timezone component. + + + + + + + + Z + + + + + + + + + + + + + + + + - + + + + + + + + + + + +
diff --git a/src/optional/xsl/gnucash-gnccustomer-vcard2.xsl b/src/optional/xsl/gnucash-gnccustomer-vcard2.xsl new file mode 100644 index 0000000000..e0aa735f3d --- /dev/null +++ b/src/optional/xsl/gnucash-gnccustomer-vcard2.xsl @@ -0,0 +1,74 @@ + + + + + + + + + + TEL;TYPE=WORK: + + TEL;TYPE=FAX: + + EMAIL: + + ADR;TYPE=work:;; + + ; + + ; + + ; + + N: + + + + + + + + + + + + + + + + BEGIN:VCARD VERSION:2.1 + + + + END:VCARD + + + + diff --git a/src/optional/xsl/gnucash-std.xsl b/src/optional/xsl/gnucash-std.xsl new file mode 100644 index 0000000000..d4667c3cb8 --- /dev/null +++ b/src/optional/xsl/gnucash-std.xsl @@ -0,0 +1,140 @@ + + + + + + + + + en + iso-8859-15 + + + + + + + + + + + + + + + + + + + + + _ + + + + + + + + + + + + _ + + + + + + + ; + + + _ + + + + + + + + + + this address panel can be located precisely using CSS + +
+

Customer address

+

+ + + + +
+ + +
+ + +
+ + +
+ + +
+ + +
+
+ + +

+
+
+ + + + + + + , + + + \, + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/optional/xsl/string.xsl b/src/optional/xsl/string.xsl new file mode 100644 index 0000000000..d816ffcdab --- /dev/null +++ b/src/optional/xsl/string.xsl @@ -0,0 +1,1233 @@ + + + + + + + + $Id: string.xsl,v 1.1.2.1 2006/02/28 08:47:05 neil Exp $ + + + Ball + Steve + + + 2002 + 2001 + Steve Ball + + + + String Processing + + +
+ Introduction + + This module provides templates for manipulating strings. + +
+
+ +
+ + + + + + + + + + + + + Make string uppercase + + + Converts all lowercase letters to uppercase. + + + + + + text + + The string to be converted + + + + + + + Returns string with all uppercase letters. + + + + + + + + + + + + + + ß + + + S + S + + + + + + + + + Make string lowercase + + + Converts all uppercase letters to lowercase. + + + + + + text + + The string to be converted + + + + + + + Returns string with all lowercase letters. + + + + + + + + + + + Capitalise string + + + Converts first character of string to an uppercase letter. All remaining characters are converted to lowercase. + + + + + + text + + The string to be capitalised + + + + all + + Boolean controlling whether all words in the string are capitalised. + Default is true. + + + + + + + Returns string with first character uppcase and all remaining characters lowercase. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Convert a string to one camelcase word + + + Converts a string to one lowerCamelCase or UpperCamelCase + word, depending on the setting of the "upper" + parameter. UpperCamelCase is also called MixedCase while + lowerCamelCase is also called just camelCase. The template + removes any spaces, tabs and slashes, but doesn't deal with + other punctuation. It's purpose is to convert strings like + "hollow timber flush door" to a term suitable as identifier or + XML tag like "HollowTimberFlushDoor". + + + + + + + text + + The string to be capitalised + + + + upper + + Boolean controlling whether the string becomes an + UpperCamelCase word or a lowerCamelCase word. + Default is true. + + + + + + + Returns string with first character uppcase and all remaining characters lowercase. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + String extraction + + + Extracts the portion of string 'text' which occurs before any of the characters in string 'chars'. + + + + + + text + + The string from which to extract a substring. + + + + chars + + The string containing characters to find. + + + + + + + Returns string. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + String extraction + + + Extracts the portion of string 'text' which occurs after the last of the character in string 'chars'. + + + + + + text + + The string from which to extract a substring. + + + + chars + + The string containing characters to find. + + + + + + + Returns string. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + String extraction + + + Extracts the portion of string 'text' which occurs before the first character of the last occurance of string 'chars'. + + + + + + text + + The string from which to extract a substring. + + + + chars + + The string containing characters to find. + + + + + + + Returns string. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + String substitution + + + Substitute 'replace' for 'with' in string 'text'. + + + + + + text + + The string upon which to perform substitution. + + + + replace + + The string to substitute. + + + + with + + The string to be substituted. + + + + disable-output-escaping + + A value of yes indicates that the result should have output escaping disabled. Any other value allows normal escaping of text values. The default is to enable output escaping. + + + + + + + Returns string. + + + + + + + + no + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Count Substrings + + + Counts the number of times a substring occurs in a string. This can also counts the number of times a character occurs in a string, since a character is simply a string of length 1. + + + + Counting Lines + + + + +]]> + + + + + + text + + The source string. + + + + chars + + The substring to count. + + + + + + + Returns a non-negative integer value. + + + + + + + + + + 0 + + + + + + + + + + + + 0 + + + + + + String extraction + + Extracts the portion of a 'char' delimited 'text' string "array" at a given 'position'. + + + + + text + + The string from which to extract a substring. + + + + chars + + delimiters + + + + position + + position of the elements + + + + all + + If true all of the remaining string is returned, otherwise only the element at the given position is returned. Default: false(). + + + + + + Returns string. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + String extraction + + Extracts the portion of a 'char' delimited 'text' string "array" at a given 'position' + + + + + text + + The string from which to extract a substring. + + + + chars + + delimiters + + + + position + + position of the elements + + + + + + Returns string. + + + + + + + + + + + + + + + + + + + + + + + + + + + String insertion + + Insert 'chars' into "text' at any given "position' + + + + + text + + The string upon which to perform insertion + + + + position + + the position where insertion will be performed + + + + with + + The string to be inserted + + + + + + Returns string. + + + + + + + + + + + + + + + + + String reversal + + + Reverse the content of a given string + + + + + + text + + The string to be reversed + + + + + + + Returns string. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Format a string + + + Inserts newlines and spaces into a string to format it as a block of text. + + + + + + text + + String to be formatted. + + + + max + + Maximum line length. + + + + indent + + Number of spaces to insert at the beginning of each line. + + + + justify + + Justify left, right or both. Not currently implemented (fixed at "left"). + + + + + + + Formatted block of text. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Find first occurring character in a string + + + Finds which of the given characters occurs first in a string. + + + + + + text + + The source string. + + + + chars + + The characters to search for. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Match A String To A Pattern + + + Performs globbing-style pattern matching on a string. + + + + Match Pattern + + + + +]]> + + + + + + text + + The source string. + + + + pattern + + The pattern to match against. Certain characters have special meaning: + + + * + + Matches zero or more characters. + + + + ? + + Matches a single character. + + + + \ + + Character escape. The next character is taken as a literal character. + + + + + + + + + + Returns "1" if the string matches the pattern, "0" otherwise. + + + + + + + + + + + 1 + + + 1 + + + 0 + + + + + + + + + + + + + + + + + + + + + + 0 + + + + 1 + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + 1 + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + Create A Repeating Sequence of Characters + + + Repeats a string a given number of times. + + + + + + text + + The string to repeat. + + + + count + + The number of times to repeat the string. + + + + + + + + + + + + + + + + + + + + + + +
+ diff --git a/src/optional/xsl/vcard-gnccustomer.pl b/src/optional/xsl/vcard-gnccustomer.pl new file mode 100755 index 0000000000..2938fa32c2 --- /dev/null +++ b/src/optional/xsl/vcard-gnccustomer.pl @@ -0,0 +1,103 @@ +#!/usr/bin/perl -w + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +use Text::vCard::Addressbook; +use strict; +use vars qw($address_book $hex_string $num $c $d $e $i $vcard $names $name $fullname $email $address $addresses $phones $phone $filename $usage $encoding); + +############### USER CONFIGURATION #################### +# Change to the encoding for you locale if your VCF data +# contains accented characters etc. + $encoding = 'UTF-8'; +############### END CONFIGURATION #################### + +# About +# +# This is a very simple file and should be simple to customise. +# A similar file is included in pilot-qof. Currently, the script +# needs to be told where to find the VCF file to transform and +# expects the user to redirect output to a file: +# $ perl vcard-gnccustomer.pl contact.vcf > contact.xml + + $usage = $#ARGV + 1; + if($usage < 1) + { + print ("Error: please specify a .vcf file.\n\n"); + exit; + } + $filename = $ARGV[0]; + $address_book = Text::vCard::Addressbook->new({ + 'source_file' => $filename, }); + # generate a temporary GUID to relate the address to the customer + $hex_string = ''; + for($d = 1;$d < 5;$d++) + { + for($c = 1; $c < 8; $c++) + { + $num = (int(rand(99)) + 1) * 10**$c; + } + $hex_string .= sprintf("%x", $num); + } + print "\n"; + print "\n"; + print " \n"; + print " \n"; + print " \n"; + foreach $vcard ($address_book->vcards()) { + $names = $vcard->get({ 'node_type' => 'name' }); + foreach $name (@{$names}){ + if($name->given()) { + $fullname = $name->given() . " " . $name->family(); + } + else { + $fullname = $name->family(); + } + &wrap_in_qsf($fullname, "name"); + } + $phones = $vcard->get('tel'); + $i = 0; + foreach $phone (@{$phones}){ + if($i == 0) { + &wrap_in_qsf($phone->value(), "phone"); + } + if($i == 1) { + &wrap_in_qsf($phone->value(), "fax"); + } + $i++; + } + $email = $vcard->get('email'); + foreach $e (@{$email}){ &wrap_in_qsf($e->value(), "email"); } + $addresses = $vcard->get({ 'node_type' => 'addresses' }); + foreach $address (@{$addresses}) { + &wrap_in_qsf($address->street(), "street"); + &wrap_in_qsf($address->city(), "city"); + &wrap_in_qsf($address->region(), "locality"); + } + print " $hex_string\n"; + } + print " \n"; + print " \n"; + &wrap_in_qsf($fullname, "name"); + print " true$hex_string\n"; + print " \n"; + print "\n\n"; + +sub wrap_in_qsf() +{ + if($_[0]) { print " $_[0]\n"; } + else { print " \n"; } +};