View Single Post
  #1 (permalink)  
Old November 26th, 2009, 09:10 AM
peterdums peterdums is offline
Registered User
 
Join Date: Jan 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Xpath more specific or return tree fragment or nodes

Hi Everyone,

What can I add more in my xpath for $package-table2 variable so it will only retrieve values without the word 'option x'? (source xml below)

I tried:
Code:
  <xsl:variable  name="package-table2"  select="//Table_Body[contains(lower-case(preceding::Table_Heading[1]),'agency  certified')]/Table_Row[not(@Format='Subtitle')]/Table_Cell[@colname='1'][substring-before(  text(), 'option' )] "/> 
but output is:
Code:
    <uu>DOP-8, 400 mile , option 6</uu>
   <uu>AMD-8, option 7</uu>
   <uu>AMD-8, option 9</uu>
desired output:
Code:
   <pp>DOP-8</pp>
   <pp>DOP-8, 400 mile ,</pp>
   <pp>AMD-8,</pp>
   <pp>AMD-8,</pp>
   <pp>DOP-8</pp>
   <pp>DOP-8, 400 mile,</pp>
    <pp>AMD-8,</pp>
   <pp>AMD-8,</pp>
Reason why I just wanted to get the desired output above so that i can use distinct-values without having to worry to create another template to remove the text 'option x'. So I can directly use distinct-values from the extracted value of the variable where it is still 'tree fragment' or 'nodes'. I created a template and the output is considered as one. (see below)

I have a template below that accepts a list , omits the text 'option x' and removes comma at the end:

Code:
  <xsl:variable name="trimmed">
     <xsl:for-each  select="$uniq">
      <xsl:variable  name="p">
      <xsl:call-template  name="trim-package">
       <xsl:with-param name="pckg"  select="."/>
      </xsl:call-template>  
      </xsl:variable>
      <XX><xsl:sequence  select="$p"/> | </XX><!--this char is just for separator so i can  distinctly recognize  each-->
     </xsl:for-each>
    </xsl:variable>
where:
Code:
$uniq = <xsl:variable name="uniq"  select="distinct-values($package-table2 )"/>
where:
Code:
     <xsl:variable name="package-table2"  select="//Table_Body[contains(lower-case(preceding::Table_Heading[1]), 'my  table' )]/Table_Row[not(@Format='Subtitle')]/Table_Cell[@colname='1']"/>
Problem is the value returned by the template is considered as one.

output:
Code:
 <tt>DOP-8, 400 mile  |  AMD-8 |  AMD-8 |  </tt>
---------------------------------------------------------------------------------------------
What I have now:

XPATH: (source xml below)
Code:
 <xsl:variable  name="package-table2"  select="//Table_Body[contains(lower-case(preceding::Table_Heading[1]), 'my  table')]/Table_Row[not(@Format='Subtitle')]/Table_Cell[@colname='1']"/> 
i iterate:
Code:
  <xsl:for-each  select="$package-table2">
 <pp><xsl:value-of select="."/>  </pp>    
</xsl:for-each> 

RESULT:

Code:
    <pp>DOP-8</pp>
   <pp>DOP-8, 400 mile , option 6</pp>
   <pp>AMD-8,  option 7</pp>
   <pp>AMD-8, option 9</pp>
    <pp>DOP-8</pp>
    <pp>DOP-8, 400 mile , option 6</pp>
   <pp>AMD-8,  option 7</pp>
   <pp>AMD-8, option  9</pp>

To get only unique values, I used:


Code:
<xsl:variable name="uniq"  select="distinct-values($package-table2 )"/>
I iterate:
Code:
   <xsl:for-each  select="$uniq">
     <uu><xsl:value-of select="."/>  </uu>    
 </xsl:for-each>
RESULT:
Code:
  <uu>DOP-8</uu>
<uu>DOP-8, 400  mile ,  option 6</uu>
<uu> AMD-8, option 7</uu>
<uu>AMD-8, option 9</uu>
I have a template that omits the text 'option ' and removes comma at the end (if there is)

Code:
  <xsl:variable  name="trimmed">
     <xsl:for-each  select="$uniq">
      <xsl:variable  name="p">
      <xsl:call-template  name="trim-package">
       <xsl:with-param name="pckg"  select="."/>
      </xsl:call-template>  
      </xsl:variable>
      <XX><xsl:sequence  select="$p"/> |  </XX>
     </xsl:for-each>
    </xsl:variable>
    
I iterate:
Code:
     <xsl:for-each  select="$trimmed">
     <tt><xsl:value-of select="."/>  </tt>    
    </xsl:for-each> 
OUTPUT:
Code:
<tt>DOP-8 | DOP-8, 400 mile    |  AMD-8 |  AMD-8 | </tt>
Problem is it is stored as one.

My desired output would be like 'tree fragments' or 'nodes'

Code:
  <tt>DOP-8 | </tt>
 <tt>DOP-8, 400 mile  | </tt>
 <tt> AMD-8 | </tt>
 <tt> AMD-8 | </tt>
So i can again use distinct-values:

Code:
 <xsl:variable  name="uniq-again" select="distinct-values($trimmed )"/>
so desired output would be:

Code:
 <tt>DOP-8 | </tt>
 <tt>DOP-8, 400 mile  | </tt>
 <tt>AMD-8 | </tt>
Now only one AMD-8

i'll just then remove the '|' from another template.

--------------------------------

SOURCE XML:
Code:
 <Table Format =  "Across_All_Columns"><Table_Grid>
<Table_Heading>
<Table_Title  Format = "Subtitle">
<Table_Title_Cell colname = "1"> My  Table/
Package</Table_Title_Cell>
<Table_Title_Cell  namest = "2" nameend = "6">The  BIN</Table_Title_Cell>
</Table_Title>
</Table_Heading>
<Table_Body>
<Table_Row  Format = "Subtitle" rowsep = "1">
<Table_Cell colname =  "1"><Bold>UL</Bold></Table_Cell>
...
<Table_Cell  colname = "6">ABCD</Table_Cell>
</Table_Row>
<Table_Row  rowsep = "1">
<Table_Cell colname = "1">DOP-8</Table_Cell>
...
<Table_Cell  colname = "6">ABCD</Table_Cell>
</Table_Row>
<Table_Row  rowsep = "1">
<Table_Cell colname = "1">DOP-8, 400 mile , option  6</Table_Cell>
...
<Table_Cell colname =  "6">ABCD</Table_Cell>
</Table_Row>
<Table_Row rowsep =  "1">
<Table_Cell colname = "1"> AMD-8, option  7</Table_Cell>
...
<Table_Cell colname =  "6">ABCD</Table_Cell>
</Table_Row>
<Table_Row rowsep =  "1">
<Table_Cell colname = "1"> AMD-8, option  9</Table_Cell>
...
<Table_Cell colname =  "6">ABCD</Table_Cell>
</Table_Row>
<Table_Row Format =  "Subtitle" rowsep = "1">
<Table_Cell colname = "1"><Bold> VDE,  UL</Bold></Table_Cell>
...
<Table_Cell colname =  "6">ABCD</Table_Cell>
</Table_Row>
<Table_Row rowsep =  "1">
<Table_Cell colname = "1">DOP-8</Table_Cell>
...
<Table_Cell  colname = "6">ABCD</Table_Cell>
</Table_Row>
<Table_Row  rowsep = "1">
<Table_Cell colname = "1">DOP-8, 400 mile, option  6</Table_Cell>
...
<Table_Cell colname =  "6">ABCD</Table_Cell>
</Table_Row>
<Table_Row rowsep =  "1">
<Table_Cell colname = "1"> AMD-8, option  7</Table_Cell>
...
<Table_Cell colname =  "6">ABCD></Table_Cell>
</Table_Row>
<Table_Row rowsep  = "0">
<Table_Cell colname = "1"> AMD-8, option  9</Table_Cell>
...
<Table_Cell colname =  "6">ABCD</Table_Cell>
</Table_Row>
</Table_Body>
Thanks in advance for the help!