[xsl] dynamically generating css

Subject: [xsl] dynamically generating css
From: Bruce D'Arcus <bdarcus@xxxxxxxxxxxxx>
Date: Mon, 30 Aug 2004 17:21:48 -0400
A couple of weeks back, Jeni helped me with a suggestion on how to read an external (non-xsl) xml file to configure output formatting. So one big part of this is it should iterate over the elements and create CSS definitions where there are appropriate attributes.

I'm making progress on this, but I'm stuck in only get one element output.

So, I have this input:

	<reftype name="book">
	  <creator after=" ">
	    <name/>
	    <role before=" "/>
	  </creator>
	  <date after=". ">
	    <year/>
	  </date>
	  <title font-style="italic" after=". "/>
	  <genre after=" "/>
	  <medium before="[" after="], "/>
	  <origin>
	    <place/>
	    <publisher before=":"/>
	  </origin>
	  <physical-location before=", available at "/>
	  <url/>
	</reftype>
	<reftype name="chapter">
	  <creator/>
	  <date before=" " after=". ">
	    <year/>
	  </date>
	  <title after=". "/>
	  <container before="In ">
	    <title font-style="italic" after=", "/>
	    <creator>
	      <role after=" "/>
	      <name/>
	    </creator>
	    <part-details before=", ">
	      <pages/>
	    </part-details>
	    <origin before=".">
	      <place/>
	      <publisher before=":"/>
	    </origin>
	  </container>
	  <genre before=", "/>
	  <medium before="(" after="), "/>
	  <physical-location/>
	  <url/>
	</reftype>

I get this output:

..book-title{
font-style: italic;
  }

This is correct as far it goes, but I need the other definitions too. In this case, I should also get:

..chapter-container-title{
font-style: italic;
  }

Stylesheet, where I obviously am doing something wrong with the cs:reftype template):

  <xsl:template name="css" match="cs:citationstyle">
    <xsl:apply-templates select="//cs:reftype"/>
  </xsl:template>

<xsl:template match="cs:reftype">
<xsl:param name="style" as="element()" select="."/>
<xsl:variable name="reftype-name" select="@name"/>
<xsl:variable name="source" as="element()" select="." />
<xsl:for-each select="$style/*[@font-style | @font-weight]">
..<xsl:value-of select="$reftype-name"/>-<xsl:value-of select="name(.)"/>{<xsl:apply-templates
select="$source/*[node-name(.) = node-name(current())]">
<xsl:with-param name="style" select="." />
</xsl:apply-templates>}
</xsl:for-each>
</xsl:template>


<xsl:template match="cs:*">
<xsl:apply-templates select="@font-family | @font-style | @font-weight"/>
</xsl:template>


  <xsl:template match="@font-family">
font-family: <xsl:value-of select="."/>;
  </xsl:template>

  <xsl:template match="@font-style">
font-style: <xsl:value-of select="."/>;
  </xsl:template>

  <xsl:template match="@font-weight">
font-weight: <xsl:value-of select="."/>;
  </xsl:template>

Bruce

Current Thread