Solved

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

Posted on 2009-07-03
9
1,027 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
  • 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
 

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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 500 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
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…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

758 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now