Altova Mailing List Archives


Re: [xsl] Help with regex

From: Brandon Ibach <brandon.ibach@---------------.--->
To: xsl-list <xsl-list@-----.------------.--->
Date: 4/2/2011 8:47:00 PM
Let's take a step back, for a moment, to gather some basics.  Are you
using XSLT 1.0 or XSLT 2.0?  I believe oXygen supports both, but I'm
not familiar with the details.  Your code indicates it is 1.0, but is
most definitely attempting to use 2.0 features.

More importantly, your code is badly malformed.  An XSLT transform
must be a well-formed XML document.  oXygen is raising an error on the
"xsl:count" because it is not a well-formed XML element.  Beyond that,
xsl:count, xsl:sum and xsl:string are not XSLT elements/instructions
(in either version) and you appear to be using "as" to assign results
to variables, rather than using an xsl:variable instruction, as shown
near the top of your transform.  Finally, the xsl:function needs to be
at the top level of your transform, rather than inside an
xsl:template.

Those are (most of) the basic syntax and usage errors.  You also have
logic errors, but I wouldn't spend too much time on that until you've
got a basic grasp on how to write valid XSLT.  I can write you an XSLT
transform that does what you've described, but if you're really trying
to learn XSLT well enough to do productive work in it (beyond passing
a class), I doubt that's going to help you achieve that goal.

I suggest you focus on the basics with a good book or tutorial
(http://www.w3.org/Style/XSL/ lists several, or just type "XSLT
tutorial" into Google), then take another try at this problem.  Feel
free to come back here with further questions, but I'd bet that you'll
get better response to a transform that successfully runs, but doesn't
quite produce the right result than one that doesn't run at all due to
errors in the basic syntax and usage.

Good luck and good learning. :)

-Brandon :)


On Sat, Apr 2, 2011 at 3:52 PM, Ginny Wagner <ginnywagner@s...> wrote:
> The following is a system that will relate various names(citations) from
> various sources to a specific person. I need to bring the sourceref and the
> personref into equal strings with the matching ids in their xml pages. I
> have over 90,000 name records that need to be translated properly so that
> the refid will match the id in the other xml docs.
>
> name.xml
> <names>
> <citation>
> <name id="N000002"/>
> <forename>Bob</forename>
> <descriptor>Jones</descriptor>
> <sourceref refid="S3568"/>
> <source>ww</source>
> <edition>1995</edition>
> <reference>p. 254</reference>
> <personref refid="P875"/>
> <knownby>Robert Jones</knownby>
> </citation>
> <citation>
> <name id="N000005"/>
> <forename>Stretch</forename>
> <descriptor>Jones</descriptor>
> <sourceref refid="S10312"/>
> <source>ww</source>
> <edition>1998</edition>
> <reference>p. 189</reference>
> <personref refid="P875"/>
> <knownby>Robert Jones</knownby>
> </citation>
> </<names>
>
> person.xml
> <person id="P000875" security="private" knownby="Robert Jones" gender="male"
> status="Artist" provenance="England" existence="deceased" family="yes"
> county="York" pnotes="He created over one thousand paintings most of which
> now hang in museums across the United States and Canada. His son, Robert
> Jones, Jr. built the Jones Museum in London which houses over one hundred of
> his paintings as well as fifty paintings of his wife, Celia Jones. His style
> is cubist. He studied with Picasso when just a young boy."/>
>
> source.xml
> <source source-id="S003568" type="Who's Who" edition="1995" reference="page
> 94" county="London">Blah Blah Blah <name>Bob Jones</name> blah blah artist
> of the year in Brussels.
> <notes></notes></source>
> <source source-id="S010312" type="Who's Who" edition="1998" reference="page
> 98" county="London">Blah Blah Blah <name>Stretch Jones</name> blah blah
> artist of the year in Paris.
> <notes>Toured the United States in 1997.</notes></source>
>
> The psuedo code I have is come up with is:
>
> Left 1 = var Y:  var Y=P or S
> Find resultant length and store in var X: 875, 3568, 10312, (3, 4, 5)
> 6- var X = var Z : 3, 2, 1
> Var Z = no. of 0 to append to var Y : P000, S00, S0
> Concatenate var Y and var Z:  P000875, S003568, S010312
>
> The result should be:
>
> name.xml
> <names>
> <citation>
> <name id="N000002"/>
> <forename>Bob</forename>
> <descriptor>Jones</descriptor>
> <sourceref refid="S003568"/>
> <source>ww</source>
> <edition>1995</edition>
> <reference>p. 254</reference>
> <personref refid="P000875"/>
> <knownby>Robert Jones</knownby>
> </citation>
> <citation>
> <name id="N000005"/>
> <forename>Stretch</forename>
> <descriptor>Jones</descriptor>
> <sourceref refid="S010312"/>
> <source>ww</source>
> <edition>1998</edition>
> <reference>p. 189</reference>
> <personref refid="P000875"/>
> <knownby>Robert Jones</knownby>
> </citation>
> </<names>
>
> My (nonworking) xsl translation is:
>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>    version="1.0">
>  <xsl:template match="/">
>    <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
>
>
>   <xsl:function name="str:characters" as="xs:string*">
>        <xsl:param name="string" as="xs:string" />
>        <xsl:if test ="$string">
>  <xsl:sequence select="substring($string, 1, 1)" as="uppercase" />
>            <xsl:variable name="remainder" select="substring($string, 2)"
> as="string" />
>            <xsl:if test="remainder">
>                <xsl:sequence select="str:characters($remainder)" />
>    <xsl:count($remainder()*) as integer/>
>  <xsl:sum(6-($remainder) as="xs:addon" />
>                <xsl:string xsl:string-join((xs:$uppercase, $addon,
> $remainder)) />
>            </xsl:if>
>        </xsl:if>
>   </xsl:function>
>  </xsl:template>
> </xsl:stylesheet>
>
> I get an error on the count statement in oXygen and I can't seem to get any
> further. Any help would be greatly appreciated!
>
> Ginny Wagner
>
>
>
>
>
> --~------------------------------------------------------------------
> XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
> or e-mail: <mailto:xsl-list-unsubscribe@l...>
> --~--
>
>

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe@l...>
--~--

Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.