Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


How to extract parent's attributes? How to use patterns to parse attribute's string value?

From: "Siegfried Heintze" <siegfried@-------.--->
To: NULL
Date: 10/17/2008 12:23:00 AM
Here is what is in my source xml:

  <g transform="translate( 40.00, 59.55)"><rect id="line 1277 rect" 
title="0002 0001 scan 001 `  ~"    width="12.5"   height="12.5" 
class="keyoutline" />   <text x=" 6" y="11" class="tch">&#24055;</text><text 
x=" 6" y="11" class="ru-up">&#516;</text><text x=" 6" y="11" 
class="ru-lo">&#517;</text> 
</g>

How do I extract the 40.00 and 59.55 from the translate attribute for each 
child that has an attribute [class='tch']?

Here is my attempt -- it is almost working. I get the text(), the @x and the 
@y but I cannot get the sibling or parent attributes! What am I doing wrong? 
I'm using saxon.

I guess this is a two part question. After I get the parent's transform 
attribute, I want to extract the two numerical values from the translation.

Thanks!
Siegfried


<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   exclude-result-prefixes="xs"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:xlink="http://www.w3.org/1999/xlink"
   xmlns:svg="http://www.w3.org/2000/svg"
   version="2.0">

   <xsl:output indent="yes"/>
   <xsl:template match="/">
     <keys>
       <xsl:apply-templates select="//svg:text[@class='tch']"/>
     </keys>
   </xsl:template>

   <xsl:template match="//*[@class='tch']">
     <xsl:element name="key">
       <xsl:attribute name="x"><xsl:value-of select="@x"/></xsl:attribute> 
<!-- works!-->
       <xsl:attribute name="title"><xsl:value-of 
select="../../svg:g[@title]"/></xsl:attribute>        <!-- does not 
work! -->
       <xsl:attribute name="width"><xsl:value-of 
select="../svg:text[@svg:width]"/></xsl:attribute>        <!-- does not 
work! -->
       <xsl:attribute name="pos"><xsl:value-of 
select="position()"/></xsl:attribute>   <!-- this seems to give the 
grandchild position and not the child position, I want the child 
position -->

       <xsl:value-of select="text()"/>
     </xsl:element>
   </xsl:template>
</xsl:stylesheet>




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent