Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > BOOK: XSLT Programmer's Reference, 2nd Edition
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: XSLT Programmer's Reference, 2nd Edition
This is the forum to discuss the Wrox book XSLT: Programmer's Reference, 2nd Edition by Michael Kay; ISBN: 9780764543814
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: XSLT Programmer's Reference, 2nd Edition section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old November 26th, 2009, 08:10 AM
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!
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying all the nodes except the specific node arunprasadlv XSLT 14 July 22nd, 2009 09:19 AM
Processing specific Nodes Krippers XSLT 3 November 6th, 2008 04:38 AM
To Select a specific nodes from XML vkommera XSLT 4 June 27th, 2008 03:39 PM
for-each on result tree fragment RoeZ XSLT 11 November 22nd, 2007 06:31 AM
Help accessing specific nodes jshl_wiz Javascript 2 June 29th, 2005 09:45 PM



All times are GMT -4. The time now is 04:00 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.