Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - How to extract parent's attributes? How to use patterns to parse attribute's string value? >Thread Next - Re: How to extract parent's attributes? How to use patterns to parse attribute's string value? Re: How to extract parent's attributes? How to use patterns to parse attribute's string value?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">巷</text><text > x=" 6" y="11" class="ru-up">Ȅ</text><text x=" 6" y="11" > class="ru-lo">ȅ</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/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
