How to convert xslt version 2.0 to version 1.0

I am using an xslt document that uses xpath version 2 functions. I only have a xalan 2.6 jar that has an xslt 1.0 processor, its restriction I cannot change it .. please help me if there are tools that convert xpath 2.0 functions to 1.0

<xsl:variable name="var1_ClinicalDocument" as="node()?" select="ns0:ClinicalDocument"/> <DSMessage> <DSPatient> <xsl:for-each select="$var1_ClinicalDocument[fn:exists(ns0:id/@root)]"> <Source> <xsl:sequence select="fn:string(ns0:id/@root)"/> </Source> </xsl:for-each> <Demographics> <xsl:for-each select="($var1_ClinicalDocument/ns0:recordTarget/ns0:patientRole/ns0:id)[fn:exists(@extension)]"> <externalID> <xsl:sequence select="fn:string(@extension)"/> </externalID> </xsl:for-each> <xsl:for-each select="($var1_ClinicalDocument/ns0:recordTarget/ns0:patientRole/ns0:patient/ns0:name/ns0:given/node())[fn:boolean(self::text())]"> <firstName> <xsl:sequence select="fn:string(.)"/> </firstName> 
+4
source share
3 answers

Here is a map of the XPath 2.0 features in question:

  XPath 2.0 XPath 1.0 Xalan-Java XSLT-C
 fn: exists () string-length (concat (.,)) XPath 1.0 XPath 1.0
 fn: string () string () XPath 1.0 XPath 1.0
 fn: boolean () boolean () XPath 1.0 XPath 1.0

The EXSLT, XSLTSL, FXSL, and XPath algorithms can fill most of the remaining functionality.

  XPath 2.0 FXSL XSLTSL EXSLT XPath 1.0
 fn: max maximum math: max
 fn: max dyn: max
 fn: min minimum math: min
 fn: min dyn: min
 fn: sum sum math: sum sum
 fn: sum dyn: sum
 fn: avg sum div count
 fn: floor floor
 fn: ceiling ceiling
 fn: round round
 fn: abs math: abs
 fn: collection foldl
 op: concatenate append
 fn: doc document
 fn: count count
 fn: not not
 fn: true true
 fn: false false
 fn: boolean boolean
 fn: upper-case str: to-upper
 fn: lower-case str: to-lower
 fn: substring substring
 fn: string-length string-length
 fn: normalize-space normalize-space
 fn: translate translate
 fn: concat str: concat concat
 fn: substring-before substring-before
 fn: substring-after substring-after
 fn: reverse str: backward
 fn: insert-before str: insert-at        
 fn: matches str: string-match
 fn: tokenize str: tokenize
 fn: resolve-uri uri: resolve-uri
 fn: distinct-values ​​set: distinct 
 op: union |
 op: intersect set: intersection
 op: except cmp: diff set: difference
 op: is-same-node cmp: cmp
 fn: position node: xpath position
 fn: last last
 fn: data node: type
 fn: lang lang
 fn: current-dateTime date: date-time
 fn: dateTime dt: format-date-time date: format-date
 fn: year-from-date dt: get-xsd-datetime-year date: day-in-year
 fn: month-from-dateTime dt: get-xsd-datetime-month date: month-name
 fn: day-from-dateTime dt: get-xsd-datetime-day date: day-name 
 fn: hours-from-dateTime dt: get-xsd-datetime-hour date: hour-in-day
 fn: minutes-from-dateTime dt: get-xsd-datetime-minute date: minute-in-hour
 fn: seconds-from-dateTime dt: get-xsd-datetime-second date: second-in-minute
 fn: timezone-from-dateTime dt: get-xsd-datetime-timezone
 if (...) then (...) else (...) $ dynamic [$ var] |  $ default [not ($ var)]

References

+3
source

I will try, but this is not verified:

 <xsl:variable name="var1_ClinicalDocument" select="ns0:ClinicalDocument"/> <DSMessage> <DSPatient> <xsl:for-each select="$var1_ClinicalDocument[ns0:id/@root]"> <Source> <xsl:value-of select="ns0:id/@root"/> </Source> </xsl:for-each> <Demographics> <xsl:for-each select="($var1_ClinicalDocument/ns0:recordTarget/ns0:patientRole/ns0:id)[@extension]"> <externalID> <xsl:value-of select="@extension"/> </externalID> </xsl:for-each> <xsl:for-each select="($var1_ClinicalDocument/ns0:recordTarget/ns0:patientRole/ns0:patient/ns0:name/ns0:given/node())[self::text()]"> <firstName> <xsl:value-of select="."/> </firstName> 

Basically the use of fn:exists , fn:string and fn:boolean can be replaced, of course, if you are using XPath / XSLT 2.0 tokenize like tokenize or for-each-group , you need more work and maybe Xalan specific extension functions .

+2
source

This should be a good translation :

  <xsl:variable name="var1_ClinicalDocument" select="ns0:ClinicalDocument"/> <DSMessage> <DSPatient> <xsl:for-each select="$var1_ClinicalDocument[ns0:id/@root]"> <Source> <xsl:value-of select="ns0:id/@root"/> </Source> </xsl:for-each> <Demographics> <xsl:for-each select= "($var1_ClinicalDocument/ns0:recordTarget /ns0:patientRole/ns0:id)[@extension]"> <externalID> <xsl:value-of select="concat(@extension, ' ')"/> </externalID> </xsl:for-each> <xsl:for-each select= "$var1_ClinicalDocument/ns0:recordTarget/ns0:patientRole /ns0:patient/ns0:name/ns0:given/text()"> <firstName> <xsl:value-of select="."/> </firstName> </xsl:for-each> </Demographics> </DSPatient> </DSMessage> 
+1
source

Source: https://habr.com/ru/post/1481990/


All Articles