?
Solved

Why can I not have  <xsl:analyze-string> in <xsl:template>

Posted on 2009-07-03
9
Medium Priority
?
1,049 Views
Last Modified: 2013-11-18
When I try and transform my data with my stylesheet I get the error:

"Keyword xsl:template may not contain xsl:analyze-string"

My template looks like this:

<xsl:template name="CheckValid">        
  <xsl:param name="Textstr"/>
  <xsl:param name="Expression"/>
  <xsl:param name="Replacestr"/>
   <xsl:param name="Type"/>
    <xsl:analyze-string select="$Textstr" regex="$Expression">
          <xsl:matching-substring>
              <xsl:choose>
                 <xsl:when test="$Type = 'date'">
                      <xsl:call-template name="InternationalizeDate">
                         <xsl:with-param name="Datestr" select="$Textstr"/>
                      </xsl:call-template>
                 </xsl:when>
                 <xsl:otherwise>
         <xsl:value-of select="$Textstr"/>    
                 </xsl:otherwise>
              </xsl:choose>
            </xsl:matching-substring>
            <xsl:non-matching-substring>
                <xsl:value-of select="$Replacestr"/>      
            </xsl:non-matching-substring>
         </xsl:analyze-string>
       </xsl:template>

The InternationalizeDate template is as follows:

<xsl:template name="InternationalizeDate">
  <xsl:param name="Datestr"/>
       <xsl:value-of select="concat(substring($Datestr, 7, 4), '/', substring($Datestr, 4, 2), '/',
                                  substring($Datestr, 1, 2))"/>
</xsl:template>    

and finally I call my CheckValid template as follows:

<DateofBirth>
<xsl:if test="normalize-space(Cell[12]/Data) != ''">                  
  <xsl:call-template name="CheckValid">                  
      <xsl:with-param name="Textstr" select="Cell[12]/Data"/>            
     <xsl:with-param name="Expression" select="$dateregexp"/>            
     <xsl:with-param name="Replacestr" select="''"/>
     <xsl:with-param name="Type" select="date"/>                  
  </xsl:call-template>                  
</xsl:if>
</DateofBirth>

Finally the dateregexp param is defined as follows:
<xsl:param name="dateregexp" select="'([0]?[1-9]|[12][0-9]|3[01])[-/ .]([0]?[1-9]|1[012])[-/ .](19|20)\d\d'"></xsl:param>
      
Can anyone see what I am doing wrong?  I have defined my stylesheet as using version 2.0.

Any help much appreciated.
Thanks
Sam


0
Comment
Question by:Samm1502
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24770938
I will have a look in a minute,
but are you sure that you are using a XSLT2 processor?
you should use Saxon9 (or some other XSLT2 processor- for that
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24770991
My bet is that you are not using an XSLT2 processor,
there is nothing wrong with your code

analyze-string does not like empty strings as an input, som make sure that $Textstr can not be empty
0
 

Author Comment

by:Samm1502
ID: 24771175
How do I find out what XSLT processor I am using?  I didn't install one I am using whatever came with XP as far as I am aware.

Cheers
Sam
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Samm1502
ID: 24771198
I should add that I calling the Transform method from a VB6 executable (not VB.NET) so not sure I can use Saxon9 as for Java or .NET and my VB calls are like this:

Dim objXSL As MSXML2.DOMDocument
Dim objXML As MSXML2.DOMDocument
Dim strXSLFilePath As String

strXSLFilePath = Get_StyleSheet(strFormat)

Set objXSL = CreateObject("MSXML2.DOMDocument.4.0")
   
'Turn off asyncronous file loading.
objXSL.async = False
 objXSL.Load (strXSLFilePath)
   
Transform_FileData = objXML.transformNode(objXSL)
   
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24771255
OK, you are using msxml. That is a XSLT1 processor, you can not use XSLT2 functionality with msxml
You can use Saxon in .net,
you can not use saxon in classic vb.

So you either port your application to .net or you port your stylesheet to XSLT1

Note that inside msxsl you can use JavaScript.
Given that the regex you have could be a daunting task in XSLT1,
I might recommend that you develop that part in JavaScript inside the XSLT
0
 

Author Comment

by:Samm1502
ID: 24779420
Do you possibly have any good examples showing how to use Javascript within XSLT as porting my application to .NET is out o fthe question within the current available time frame.

Muh apreciated.
Thanks
Sam
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 total points
ID: 24779863
Here is a simple straightforward example of using JavaScript in an msxml xslt processor

you need to declare
      xmlns:msxsl="urn:schemas-microsoft-com:xslt"
and a namespace for your javascript function
      xmlns:myjs="urn:internal:my-javascript">
(could be a different prefix and namespace, as long as you have one it is OK)
Then have a script tag in the msxsl namespace and implement the namespace by setting the prefix
      <msxsl:script language="JavaScript" implements-prefix="myjs">
in this block, define your javascript functions (here you make a function that processes the text by a regex)
works well, the reason I don't do this very often is that it binds your xslt to one specific processor
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns:msxsl="urn:schemas-microsoft-com:xslt"
	xmlns:myjs="urn:internal:my-javascript">
	<msxsl:script language="JavaScript" implements-prefix="myjs">
	<![CDATA[
		function GetCurrentDateTime()
		{
		var currentTime = new Date();
		var month = currentTime.getMonth() + 1;
		var day = currentTime.getDate();
		var year = currentTime.getFullYear();
		return(month + "/" + day + "/" + year);
		}
	]]>
	</msxsl:script>
 
<xsl:template match="/">
	<xsl:value-of select="myjs:GetCurrentDateTime()"/>
</xsl:template>
 
</xsl:stylesheet>

Open in new window

0
 

Author Closing Comment

by:Samm1502
ID: 31599490
Thanks a million that's just what I need.  Much appreciated.
Sam
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24791681
welcome
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question