[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: passing a regex matched substring to the result-d

Subject: Re: passing a regex matched substring to the result-document
From: Manuel Souto Pico <m.soutopico@xxxxxxxxx>
Date: Fri, 4 Sep 2009 22:43:04 +0200
Re:  passing a regex matched substring to the  result-d
Hi Martin,

Thanks for your reply. Your suggestion helps but unfortunately not as
much as to get this thing done.

If I don't include a name in the instantiation (?) of the variable
common, as you suggest, Saxon-B 9.1.0.3 complains, doesn't actually
compile and issues a message that says "F Element must have a "name"
attribute".

<xsl:variable name="srcfilename" select="base-uri(/)"/>
<xsl:variable name="common">
	<xsl:analyze-string select="$srcfilename" regex=".+/([^/]+)\.(XLF|xlf)">
		<xsl:matching-substring>
			<xsl:variable select="regex-group(1)"/>
		</xsl:matching-substring>
	</xsl:analyze-string>
</xsl:variable>

If I include the name attribute, it compiles but it seems as if the
variable common doesn't get any content. It gives the message "A
variable with no following sibling instructions has no effect"

<xsl:variable name="srcfilename" select="base-uri(/)"/>
<xsl:variable name="common">
	<xsl:analyze-string select="$srcfilename" regex=".+/([^/]+)\.(XLF|xlf)">
		<xsl:matching-substring>
			<xsl:variable name="common" select="regex-group(1)"/>
		</xsl:matching-substring>
	</xsl:analyze-string>
</xsl:variable>

Any other ideas?

Cheers, Manuel

PS: My whole code:

___XSLT___

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
	<xsl:output method="xml" encoding="UTF-16" standalone="no" name="xml"
indent="yes"/>
	<xsl:strip-space elements="*"/>
	<xsl:template match="/">
		<xsl:for-each select="//file">
			<xsl:variable name="srcfilename" select="base-uri(/)"/>
			<xsl:variable name="common">
				<xsl:analyze-string select="$srcfilename" regex=".+/([^/]+)\.(XLF|xlf)">
					<xsl:matching-substring>
						<xsl:variable name="common" select="regex-group(1)"/>
					</xsl:matching-substring>
				</xsl:analyze-string>
			</xsl:variable>
			<xsl:variable name="newfilename"
				select="concat('output1/', $common, '_', @target-language, '.xlf')"/>
			<xsl:value-of select="$newfilename"/>	<!-- Creating  -->
			<xsl:result-document href="{$newfilename}" format="xml">
				<xliff version="1.0">
					<newname>
						<xsl:value-of select="$newfilename"/>
					</newname>
					<xsl:copy-of select="."/>
				</xliff>
			</xsl:result-document>
		</xsl:for-each>
	</xsl:template>
</xsl:stylesheet>

___DATA___

<?xml version="1.0" encoding="UTF-8"?>
<xliff version="1.0">
	<file target-language="es">
		<body>
			<trans-unit">
				<source>Text in source language</source>
				<target state="user:untranslated">The translation goes here</target>
			</trans-unit>
			<trans-unit">
				<source>Text in source language</source>
				<target state="user:untranslated">The translation goes here</target>
			</trans-unit>
		</body>
	</file>
	<file target-language="GL">
		<body>
			<trans-unit">
				<source>Text in source language</source>
				<target state="user:untranslated">The translation goes here</target>
			</trans-unit>
			<trans-unit">
				<source>Text in source language</source>
				<target state="user:untranslated">The translation goes here</target>
			</trans-unit>
		</body>
	</file>
</xliff>


2009/9/4 Martin Honnen <Martin.Honnen@xxxxxx>:
> Manuel Souto Pico wrote:
>
>> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>> version="2.0">
>>   <xsl:output method="xml" encoding="UTF-16" standalone="no" name="xml"
>> indent="yes"/>
>>   <xsl:strip-space elements="*" />
>>   <xsl:template match="/">
>>             <xsl:param name="COMMON"/>                    <xsl:for-each
>> select="//file">
>>                     <xsl:variable name="srcfilename"
>> select="base-uri(/)"/>
>>           <xsl:analyze-string select="$srcfilename"
>> regex=".+/([^/]+)\.(XLF|xlf)">
>>               <xsl:matching-substring>
>>                   <xsl:variable name="COMMON" select="regex-group(1)"/>
>>                   <xsl:value-of select="$COMMON" /> <!-- Creating?? -->
>>               </xsl:matching-substring>
>>           </xsl:analyze-string>
>
> I think you want
>   <xsl:variable name="common">
>           <xsl:analyze-string select="$srcfilename"
> regex=".+/([^/]+)\.(XLF|xlf)">
>               <xsl:matching-substring>
>                   <xsl:value-of select="regex-group(1)"/>
>               </xsl:matching-substring>
>           </xsl:analyze-string>
>   </xsl:variable>
> to store the matched group in the variable named common.
>
> Then you can use that variable in e.g.
>
>>                     <xsl:variable name="newfilename"
>>
>> select="concat('output1/',$COMMON,_,@target-language,'.xlf')" />
>
>  select="concat('output1/', $common, @target_language, '.xlf')"/>
>
>
>
> --
>
>        Martin Honnen
>        http://msmvps.com/blogs/martin_honnen/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.