Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


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

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 10/17/2008 1:09:00 PM
Siegfried Heintze wrote:
> 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.


>    <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! -->

It is not clear what you want to achieve above. Your select expression 
../../svg:g[@title] looks at svg:g children of the grandparent element 
having a title attribute. If you want to output the title attribute 
value then you need ../../svg:g[@title]/@title.
As your SVG sample above does not have any g element with a title 
attribute I can't tell which expression you are looking for.

Also note that in XSLT 2.0 the xsl:attribute element allows a select 
attribute so you can shorten e.g.
   <xsl:attribute name="foo">
     <xsl:value-of select="bar"/>
   </xsl:attribute>
to e.g.
   <xsl:attribute name="foo" select="bar></xsl:attribute>

>        <xsl:attribute name="width"><xsl:value-of 
> select="../svg:text[@svg:width]"/></xsl:attribute>        <!-- does not 
> work! -->

Again it is not clear what you want to achieve. The select expression 
../svg:text[@svg:width] select svg:text children of the parent which 
have an svg:width attribute. As attributes in SVG are in no namespace I 
think you rather want
   ../svg:text[@width]
or assuming you want to output an attribute value you want
   ../svg:text[@width]/@width

>        <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 -->

position() gives the position in the currently processed nodes. As your 
xsl:apply-templates has select="//svg:text[@class='tch']" the currently 
processed nodes are svg:text elements at all levels and position() 
refers to the position in that sequence.
Look into xsl:number to get a different value: 
http://www.w3.org/TR/xslt20/#numbering-based-on-position


As for extracting the numbers in translate( 40.00, 59.55) you could use 
xsl:analyze-string for that: http://www.w3.org/TR/xslt20/#analyze-string



-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/


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