View Single Post
  #7 (permalink)  
Old September 6th, 2006, 02:34 AM
pvasudevan pvasudevan is offline
Authorized User
 
Join Date: Nov 2003
Location: , , .
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for all the inputs. The complete XSLT that I have to do the transformation is pasted below:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

  <xsl:param name="doc" select="'../userinput/comma-edw.txt'"/>

  <xsl:param name="enc" select="'UTF-8'"/>

  <xsl:param name="root" select="'UserAccessDS'"/>

  <xsl:param name="line" select="'Access'"/>

  <xsl:param name="entry" select="'ww','un','rl'"/>

  <!--
    main template
  -->
  <xsl:template match="/">
    <xsl:element name="{$root}">
      <xsl:call-template name="tLines">
        <xsl:with-param name="value" select="unparsed-text($doc, $enc)"/>
      </xsl:call-template>
    </xsl:element>
  </xsl:template>
  <!--
    tokenize lines
  -->
  <xsl:template name="tLines">
    <xsl:param name="value" select="''"/>
    <xsl:analyze-string select="$value" regex="\n|\r">
      <xsl:matching-substring/>
      <xsl:non-matching-substring>
        <xsl:element name="{$line}">
          <xsl:call-template name="tValues">
            <xsl:with-param name="value" select="."/>
          </xsl:call-template>
        </xsl:element>
      </xsl:non-matching-substring>
    </xsl:analyze-string>
  </xsl:template>

  <xsl:template name="tValues">
    <xsl:param name="value" select="''"/>
    <xsl:analyze-string select="$value" regex=",|\t">
      <xsl:matching-substring/>
      <xsl:non-matching-substring>
      <xsl:variable name="p" select="(position()+1) div 2"/>
        <xsl:element name="{$entry[$p]}">
    <xsl:choose>
        <xsl:when test="$p=5">
                  <xsl:value-of select="."/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="."/>
        </xsl:otherwise>
    </xsl:choose>
        </xsl:element>
      </xsl:non-matching-substring>
    </xsl:analyze-string>
  </xsl:template>
</xsl:stylesheet>

So Michael, the output XML that I'm trying to generate should be like given below:

<UserAccessDS>
    <Access>
        <ww>1065</ww>
        <un>steo</un>
        <rl>Enterprise:SAPPayroll</rl>
    </Access>
    <Access>
        <ww>1015</ww>
        <un>steo</un>
        <rl>Enterprise:SAPTransactionsDetail</rl>
    </Access>
</UserAccessDS>

The input data from the comma-seperated text file is like shown below:

1065,steo,PARIS_SPEND_DV_TPP,Enterprise:SAPPayroll
1015,steo,PARIS_FUTURE_LOK_TPP,Enterprise:SAPTrans actionsDetail

So as you can see in the output xml is it has a tag <rl />, which encloses the data from the 4th column in the input comma-seperated row and not the 3rd column value. For instance, <rl>Enterprise:SAPTransactionsDetail</rl> has the data from the 4th column within the <rl /> tag and not the 3rd column value PARIS_FUTURE_LOK_TPP. I understand that in the template tValues I'm supposed to handle this.

<xsl:non-matching-substring>
      <xsl:variable name="p" select="(position()+1) div 2"/>
        <xsl:element name="{$entry[$p]}">
    <xsl:choose>
        <xsl:when test="$p=5">
                  I need to select the 4th column value from the input data
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="."/>
        </xsl:otherwise>
    </xsl:choose>
        </xsl:element>
      </xsl:non-matching-substring>

In my previous attempt, I tried using following-sibling, but I failed miserably. From your recent post, I learnt that following-sibling would work only from an exiting xml tree structure and not from any kind of data.

My problem now is to read from the input data and take the 4th column value and write it within the <rl /> tag. I hope am able to clearly let you know my requirements.

Please let me know on how I could achieve this.

Many Thanks,
Praveen

Reply With Quote