xslt 2.0 - XSLT2.0 Uppercase first Letter of Regex Match -


i have a use case convert camelcase elements in xml document newcase shown:

current:

<firstname>john</firstname> <lastname>smith</lastname> <userid>5692</userid> 

desired:

<firstname>john</firstname> <lastname>smith</lastname> <userid>5692</userid> 

i must facilitate through xslt. in order this, identified regex capture camelcase requirement:

\b([a-z])([a-z]*[a-z][a-z]*)\b 

from there, have been attempting via xslt2.0 using replace function:

 replace($xmltoparse,"\b([a-z])([a-z]*[a-z][a-z]*)\b","replaced") 

for final block, want take first segment of matched regex (in lowercase segments 'l' , 'owercase' based on above regex), , use upper-case function change first segment/letter upper case (so lowercase lowercase), , every regex match in xml. unfortunately far have been unable achieve it.

would able give insight on how link together?

this transformation:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">  <xsl:output omit-xml-declaration="yes" indent="yes"/>   <xsl:template match="node()|@*">   <xsl:copy>    <xsl:apply-templates select="node()|@*"/>   </xsl:copy>  </xsl:template>   <xsl:template match=  "*[matches(name(), '[a-z]+[a-z][a-z]*')]">   <xsl:element name=    "{upper-case(substring(name(),1,1))}{substring(name(),2)}">    <xsl:apply-templates select="node()|@*"/>   </xsl:element>  </xsl:template> </xsl:stylesheet> 

when applied on provided xml fragment (wrapped single top element become well-formed xml document):

<t>     <firstname>john</firstname>     <lastname>smith</lastname>     <userid>5692</userid> </t> 

produces wanted, correct result:

<t>       <firstname>john</firstname>       <lastname>smith</lastname>       <userid>5692</userid> </t> 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -