Jump to content

how to Select sister node via text value


omegared

Recommended Posts

Here is my xml and stylehseet, reading all is not neccessary:As you can see all parameter elements have the same name so i cant select a speicifc node by name. i also cant use someting like select parameter[1] because i will be shuffling the parameter order.Basically I want to first select a parameter based on the <parameter><name> node e.g first node would be 'book name'. I dont want to output this but rather the <value> node of that parameter.As you can see i found <xsl:apply-templates select="parameter/name[. =book name]"/> but I want to ouput the <value> element of that <parameter> abd not the <name> element. Can anyone help. Many thanks. <?xml version="1.0" encoding="UTF-8"?><data> <parameters> <parameter> <name> book name </name> <description> What is the books name </description> <valuetype> String </valuetype> <value>Java: How to Program</value> <defaultValue>Sham </defaultValue> </parameter> <parameter> <name> author </name> <description> who is the author </description> <valuetype> String </valuetype> <value>O Reily</value> <defaultValue> </defaultValue> </parameter> <parameter> <name> publisher </name> <description> who is the publisher </description> <valuetype> String </valuetype> <value>penguin books</value> <defaultValue> </defaultValue> </parameter></data><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:template match="/"> <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">.... ates select="data"/> </fo:flow> </fo:page-sequence> </fo:root> </xsl:template> <xsl:template match="data"> <fo:block> <xsl:apply-templates select="parameter/name[. =author]"/> <fo:block text-align="center" display-align="center" background-color="orange"> <fo:external-graphic src="src/templates/java.gif" scaling="non-uniform" content-width="6cm" content-height="10cm"/> </fo:block> <xsl:apply-templates select="parameter[2]"/> <xsl:apply-templates select="parameter[3]"/> </fo:block> </xsl:template> <xsl:template match="parameter[3]"> <fo:block font-size="20pt" font-family="sans-serif" space-after.optimum="20pt" space-before.optimum="12pt" text-align="center" line-height="15pt"> <xsl:value-of select="value"/>publications </fo:block></xsl:template><xsl:template match="parameter[2]"> <fo:block font-size="20pt" font-style="italic" font-family="sans-serif" line-height="15pt" space-after.optimum="30pt" space-before.optimum="40pt" text-align="center">By <xsl:value-of select="value"/> </fo:block></xsl:template><xsl:template match="parameter/name[. =author]"> <fo:block font-size="28pt" font-weight="bold" font-family="sans-serif" line-height="10pt" space-after.optimum="30pt" space-before.optimum="200pt" text-align="center"> <xsl:value-of select=""/> </fo:block></xsl:template> </xsl:stylesheet>

Link to comment
Share on other sites

Hve you tryed something more of the lines

<xsl:apply-templates select="parameter[name='book name']/value"/>

This should output the value of a parameter which has a name element inside which value is "book name". It should work, but if it doesn't, you could try something like

<xsl:apply-templates select="parameter/value[string(../name)='book name']"/>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...