Jump to content

Question About Variables With Conditional And Templates


dswitzer

Recommended Posts

Hi there. I'm new to xslt but I've done a fair amount of research on it in the last couple of days. I'm missing something when it comes to variables, though. What I would like to do is check the value of a field (ows_Style) and if it's equal to something ('~New~Paragraph~') then set a variable (Prefix) to some value ('abc') so that I can add that value to the output. In my current output I'm displaying 'aaa' and 'bbb' in order to see what gets displayed between them -- but right now nothing does. My expectation was that in my CHOOSE statement one of the two parts (the WHEN or the OTHERWISE) would be executed no matter what, so $Prefix would have either the value 'abc' or the value 'xyz'. If you could let me know what I need to do to make this work, I'd really appreciate it. Here's my xml:

<?xml version="1.0" encoding="UTF-8"?><listitems xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema" > <rs:data ItemCount="883">  <z:row ows_LookupKey="CANC300" ows_Priority="1.00000000000000" ows_Language="en_CA" ows_Style="~New~Paragraph~" ows_Content="MEMO TO: {var}BN_ProducerCode_Description{/var}" ows_MetaInfo="391;#" ows__ModerationStatus="0" ows__Level="1" ows_ID="391" ows_owshiddenversion="3" ows_UniqueId="391;#{D30E3EB7-238C-4989-BBDD-ED4D9F1AD8CE}" ows_FSObjType="391;#0" ows_Created="2011-12-02 10:12:29" ows_FileRef="391;#sites/coop/base/Lists/Content Pages  Sections/391_.000" />  <z:row ows_LookupKey="CANC300" ows_Priority="2.00000000000000" ows_Language="en_CA" ows_Style="~New~Paragraph~" ows_Content="DATE: {var}BN_EditEffectiveDate{/var}" ows_MetaInfo="393;#" ows__ModerationStatus="0" ows__Level="1" ows_ID="393" ows_owshiddenversion="3" ows_UniqueId="393;#{92C36A45-6B75-48E4-B03A-29EDECE4A246}" ows_FSObjType="393;#0" ows_Created="2011-12-02 10:12:29" ows_FileRef="393;#sites/coop/base/Lists/Content Pages  Sections/393_.000" /> </rs:data></listitems>

And here's my xslt:

<?xml version="1.0"?><xsl:stylesheet version="1.0" xmlns:xsl="[url="http://www.w3.org/1999/XSL/Transform"]http://www.w3.org/1999/XSL/Transform[/url]" xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema" > <xsl:output method="text" encoding="windows-1252" /> <xsl:template match="/">  <xsl:text>LookupKey,Priority,Language,Style,Content
</xsl:text>  <xsl:apply-templates select="listitems"/> </xsl:template> <xsl:template match="listitems">  <xsl:apply-templates select="rs:data"/> </xsl:template> <xsl:template match="rs:data">  <xsl:apply-templates select="z:row"/> </xsl:template> <xsl:template match="z:row">  <xsl:variable name="Prefix">   <xsl:choose>	<xsl:when test="@ows_Style = '~New~Paragraph~'">	 <xsl:copy-of select="abc" />	</xsl:when>	<xsl:otherwise>	 <xsl:copy-of select="xyz" />	</xsl:otherwise>   </xsl:choose>  </xsl:variable>  <xsl:value-of select="concat(@ows_LookupKey,',' ,format-number(@ows_Priority,'####'), ',',@ows_Language,',' ,@ows_Style,',aaa',$Prefix,'bbb')"/>  <xsl:text>
</xsl:text> </xsl:template></xsl:stylesheet>

Dave

Link to comment
Share on other sites

Well the xsl:copy-of select="abc" respectively "xyz" makes a deep copy of any "abc" respectively "xyz" child nodes of the context node which is the "row" element. The "row" elements are empty so I suspect you want to output a string with the literal content "abc" respectively "xyz". To do that you simply need

<xsl:text>abc</xsl:text>

or

<xsl:value-of select="'abc'"/>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...