简体   繁体   中英

xslt, xml to txt using substring, lowercase and concatenation

I have a xml file like the one below

<perosn>
    <data>
        <name>
            <firstName>Albert</firstName>
            <lastName>Einstein</lastName>
        </name>
    </data>
</person>

I would like to tranasform it into txt that looks like that.

txt output:

firstName,lastName,userID
Albert,Einstein,a.einst

What I want to do is to substring firstName to 1 character, substring lastName to 5 characters lower the case of both, and then concatenate them.

The problem is that I am not familiar with the syntaxt of xslt, and I came up with sth like this.

<xsl:value-of select="lower-case(concat(substring($firstName,1,2), ".", substring($lastName,1,6)))"/>

The other thin is this row " firstName,lastName,userID"

The code I have is:

 <xsl:template match="/">
        <File  xtt:separator="&#xd;&#xa;" xtt:align="left" xtt:severity="warning"  >
            <xsl:apply-templates/>
            <Header xtt:startTag =" firstName,lastName,userID" />               
        </File>       
 </xsl:template>

But I get it at the bottom not at the the top.

The lower-case function is fine in XSLT 2.0

<xsl:template match="/">
  <xsl:text>firstName,lastName,userID&#10;</xsl:text>
  <xsl:for-each select="perosn/data/name">
    <xsl:value-of select="
      concat(firstName, ',',
             lastName, ',',
             lower-case(substring(firstName,1,1)), ".",
             lower-case(substring(lastName,1,5)), '&#10;')" />
  </xsl:for-each>
</xsl:template>

In XSLT 1.0 you don't have lower-case so you have to use translate instead:

translate(firstName, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM