Variables with Company Info
Description
I have some variables from markers and paragraphs that I'd like to include into the subject and body of the email. I have a work around where I added some Settings to companyinfo.fti. I can collect the data from there, but since the product name and version is in the Map file (I'm using DITA), I'd much rather get it from my source than some setting in my ePublisher project.
Can I collect page level variables during the company-info pipeline?
Attempt #1
Here are my edits to Formats\Shared\common\companyinfo\companyinfo_content.xsl that doesn't quite work:
- Began as:
<!-- company-email --> <!-- company-email-href --> <!-- --> <wwpage:Replacement name="company-email" value="{wwprojext:GetFormatSetting('company-email', '')}" /> <wwpage:Replacement name="company-email-href" value="{concat('mailto:', wwprojext:GetFormatSetting('company-email', ''))}" />
Changed to:<!-- company-email --> <!-- company-email-href --> <!-- --> <xsl:variable name="vProductVar" select="wwprojext:GetRule('Marker', 'Select Attribute - product')"/> <xsl:variable name="vProductVariable" select="$vProductVar/wwproject:Options/wwproject:Option[@Name = 'variable']/@Value"/> <xsl:variable name="vProduct" select="wwpage:content='wwvars:$vProductVariable'"/> <xsl:variable name="vVersion" select="wwprojext:GetFormatSetting('email-version', 'Unica online help')"/> <!--This uses my Target setting override, I will change this to something that accesses a variable once it's working --> <xsl:variable name="subject" select="concat('Feedback for ', $vProduct, ' ', $vVersion, ' online help')"/> <xsl:variable name="body" select="'Please include the Help topic title in your feedback.'"/> <xsl:variable name="emailSuffix" select="concat('?subject=', $subject, '&body=', $body)"/> <xsl:variable name="emailString" select="concat(wwprojext:GetFormatSetting('company-email'), $emailSuffix)"/> <wwpage:Replacement name="company-email" value="Provide feedback on Unica documentation"/> <wwpage:Replacement name="company-email-href" value="{concat('mailto:', $emailString)}"/>
At this moment, this returns the following:
"mailto:zlawson@unica.com?subject=Feedback for false versionNumber online help&body=Please include the Help topic title in your feedback."
I don't understand why the 'false' is there. What I want is the current value of the variable. Does 'false' mean that it is not yet defined? Do I need to move this code out of companyinfo_content.xsl and into something like pages.xsl? Or can I change the company-info pipeline order?
Feedback #1
Zoe, this looks great. The issue you're running into is that wwvars:<variable name> only works as a page replacement in Page.asp, not in your standard XSL.
So, how can you get the value you want?
Let's back track a bit.
Let's assume you have a marker style named "Select Attribute - product" and you've assigned a variable name to it, say "product". You can access this in Page.asp with:
<span wwpage:content="wwvars:product">product name goes here</span>
That works because earlier, we created a page replacement:
<wwpage:Replacement name="wwvars:product" value="Great Unica Product!" />
That's the info you want to access, right?
Okay. So you can get at it, but you'll need to rearrange things a bit inside of "pages.xsl". The purpose of "pages.xsl" is to... generate your pages! It sets up all <wwpage:Condition>s and all <wwpage:Replacement>s so that we can render the Page.asp template. If you look inside there, you'll see that we create replacements as follows (this is based on Dynamic HTML, but other formats are similar):
<!-- Company Info --> <!-- --> <xsl:call-template name="CompanyInfo-Replacements"> <xsl:with-param name="ParamPageRule" select="$VarPageRule" /> <xsl:with-param name="ParamPagePath" select="$ParamSplit/@path" /> <xsl:with-param name="ParamSplits" select="$ParamSplits" /> </xsl:call-template> <!-- Breadcrumbs --> <!-- --> <wwpage:Replacement name="breadcrumbs"> <xsl:call-template name="Breadcrumbs"> <xsl:with-param name="ParamPageRule" select="$VarPageRule" /> <xsl:with-param name="ParamSplit" select="$ParamSplit" /> <xsl:with-param name="ParamBreadcrumbTOCEntry" select="$ParamBreadcrumbTOCEntry" /> </xsl:call-template> </wwpage:Replacement> <!-- Content --> <!-- --> <wwpage:Replacement name="content"> <xsl:call-template name="Content-Content"> <xsl:with-param name="ParamContent" select="$ParamContent" /> <xsl:with-param name="ParamSplits" select="$ParamSplits" /> <xsl:with-param name="ParamCargo" select="$VarCargo" /> <xsl:with-param name="ParamLinks" select="$ParamLinks" /> <xsl:with-param name="ParamTOCData" select="$ParamTOCData" /> <xsl:with-param name="ParamSplit" select="$ParamSplit" /> </xsl:call-template> <xsl:call-template name="Content-Notes"> <xsl:with-param name="ParamNotes" select="$VarNotes" /> <xsl:with-param name="ParamSplits" select="$ParamSplits" /> <xsl:with-param name="ParamCargo" select="$VarCargo" /> <xsl:with-param name="ParamLinks" select="$ParamLinks" /> <xsl:with-param name="ParamTOCData" select="$ParamTOCData" /> <xsl:with-param name="ParamSplit" select="$ParamSplit" /> </xsl:call-template> </wwpage:Replacement> <!-- Variables --> <!-- --> <xsl:variable name="VarSplitGlobalVariablesAsXML"> <xsl:call-template name="Variables-Globals-Split"> <xsl:with-param name="ParamProjectVariables" select="$GlobalProjectVariables" /> <xsl:with-param name="ParamSplit" select="$ParamSplit" /> </xsl:call-template> </xsl:variable> <xsl:variable name="VarSplitGlobalVariables" select="msxsl:node-set($VarSplitGlobalVariablesAsXML)/wwvars:Variable" /> <xsl:call-template name="Variables-Page-String-Replacements"> <xsl:with-param name="ParamVariables" select="$VarSplitGlobalVariables" /> </xsl:call-template>
Up top, you see your company info stuff being emitted and at the bottom, you see the variables being emitted. We'll need to change that. So, reorder them:
<!-- Variables --> <!-- --> <xsl:variable name="VarSplitGlobalVariablesAsXML"> <xsl:call-template name="Variables-Globals-Split"> <xsl:with-param name="ParamProjectVariables" select="$GlobalProjectVariables" /> <xsl:with-param name="ParamSplit" select="$ParamSplit" /> </xsl:call-template> </xsl:variable> <xsl:variable name="VarSplitGlobalVariables" select="msxsl:node-set($VarSplitGlobalVariablesAsXML)/wwvars:Variable" /> <xsl:call-template name="Variables-Page-String-Replacements"> <xsl:with-param name="ParamVariables" select="$VarSplitGlobalVariables" /> </xsl:call-template> <!-- Company Info --> <!-- --> <xsl:call-template name="CompanyInfo-Replacements"> <xsl:with-param name="ParamPageRule" select="$VarPageRule" /> <xsl:with-param name="ParamPagePath" select="$ParamSplit/@path" /> <xsl:with-param name="ParamSplits" select="$ParamSplits" /> </xsl:call-template> <!-- Breadcrumbs --> <!-- --> <wwpage:Replacement name="breadcrumbs"> <xsl:call-template name="Breadcrumbs"> <xsl:with-param name="ParamPageRule" select="$VarPageRule" /> <xsl:with-param name="ParamSplit" select="$ParamSplit" /> <xsl:with-param name="ParamBreadcrumbTOCEntry" select="$ParamBreadcrumbTOCEntry" /> </xsl:call-template> </wwpage:Replacement> <!-- Content --> <!-- --> <wwpage:Replacement name="content"> <xsl:call-template name="Content-Content"> <xsl:with-param name="ParamContent" select="$ParamContent" /> <xsl:with-param name="ParamSplits" select="$ParamSplits" /> <xsl:with-param name="ParamCargo" select="$VarCargo" /> <xsl:with-param name="ParamLinks" select="$ParamLinks" /> <xsl:with-param name="ParamTOCData" select="$ParamTOCData" /> <xsl:with-param name="ParamSplit" select="$ParamSplit" /> </xsl:call-template> <xsl:call-template name="Content-Notes"> <xsl:with-param name="ParamNotes" select="$VarNotes" /> <xsl:with-param name="ParamSplits" select="$ParamSplits" /> <xsl:with-param name="ParamCargo" select="$VarCargo" /> <xsl:with-param name="ParamLinks" select="$ParamLinks" /> <xsl:with-param name="ParamTOCData" select="$ParamTOCData" /> <xsl:with-param name="ParamSplit" select="$ParamSplit" /> </xsl:call-template> </wwpage:Replacement>
Now, the data you want/need can be accessed in $VarSplitGlobalVariables. Just what the heck is in that variable?
<wwvars:Variable name="copyright"> ... </wwvars:Variable> <wwvars:Variable name="product"> <wwdoc:Marker name='Select Attribute - product'> <wwdoc:TextRun> <wwdoc:Text value="Great Unica Product!" /> </wwdoc:TextRun> </wwdoc:Marker> </wwvars:Variable> <wwvars:Variable name="version"> ... </wwvars:Variable>
You can pull your product info out with:
<xsl:variable name="VarProductVariable" select="$VarSplitGlobalVariables[@name = 'product']" /> <xsl:variable name="VarProductVariableValue"> <xsl:apply-templates select="$VarProductVariable" mode="wwmode:variable-string-value" /> </xsl:variable>
The moded template, "wwmode:variable-string-value", lives in "variables.xsl" and is already loaded and ready to go inside of "pages.xsl".
Altogether, this should look something like this:
- pages.xsl
- We'll reorder the replacements so that we figure out our variables first and then pass those down to our company info template.
<!-- Variables --> <!-- --> <xsl:variable name="VarSplitGlobalVariablesAsXML"> <xsl:call-template name="Variables-Globals-Split"> <xsl:with-param name="ParamProjectVariables" select="$GlobalProjectVariables" /> <xsl:with-param name="ParamSplit" select="$ParamSplit" /> </xsl:call-template> </xsl:variable> <xsl:variable name="VarSplitGlobalVariables" select="msxsl:node-set($VarSplitGlobalVariablesAsXML)/wwvars:Variable" /> <xsl:call-template name="Variables-Page-String-Replacements"> <xsl:with-param name="ParamVariables" select="$VarSplitGlobalVariables" /> </xsl:call-template> <!-- Company Info --> <!-- --> <xsl:call-template name="CompanyInfo-Replacements"> <xsl:with-param name="ParamPageRule" select="$VarPageRule" /> <xsl:with-param name="ParamPagePath" select="$ParamSplit/@path" /> <xsl:with-param name="ParamSplits" select="$ParamSplits" /> <xsl:with-param name="ParamVariables" select="$VarSplitGlobalVariables" /> </xsl:call-template> <!-- Breadcrumbs --> <!-- --> <wwpage:Replacement name="breadcrumbs"> <xsl:call-template name="Breadcrumbs"> <xsl:with-param name="ParamPageRule" select="$VarPageRule" /> <xsl:with-param name="ParamSplit" select="$ParamSplit" /> <xsl:with-param name="ParamBreadcrumbTOCEntry" select="$ParamBreadcrumbTOCEntry" /> </xsl:call-template> </wwpage:Replacement> <!-- Content --> <!-- --> <wwpage:Replacement name="content"> <xsl:call-template name="Content-Content"> <xsl:with-param name="ParamContent" select="$ParamContent" /> <xsl:with-param name="ParamSplits" select="$ParamSplits" /> <xsl:with-param name="ParamCargo" select="$VarCargo" /> <xsl:with-param name="ParamLinks" select="$ParamLinks" /> <xsl:with-param name="ParamTOCData" select="$ParamTOCData" /> <xsl:with-param name="ParamSplit" select="$ParamSplit" /> </xsl:call-template> <xsl:call-template name="Content-Notes"> <xsl:with-param name="ParamNotes" select="$VarNotes" /> <xsl:with-param name="ParamSplits" select="$ParamSplits" /> <xsl:with-param name="ParamCargo" select="$VarCargo" /> <xsl:with-param name="ParamLinks" select="$ParamLinks" /> <xsl:with-param name="ParamTOCData" select="$ParamTOCData" /> <xsl:with-param name="ParamSplit" select="$ParamSplit" /> </xsl:call-template> </wwpage:Replacement>
We'll add on our need parameter, "ParamVariables":
<xsl:template name="CompanyInfo-Replacements"> <xsl:param name="ParamPageRule" /> <xsl:param name="ParamPagePath" /> <xsl:param name="ParamSplits" /> <xsl:param name="ParamVariables" />
and then we'll use them to set our company email info:<!-- company-email --> <!-- company-email-href --> <!-- --> <xsl:variable name="vProduct"> <xsl:apply-templates select="$ParamVariables[@name = 'product']" mode="wwmode:variable-string-value" /> </xsl:variable> <xsl:variable name="vVersion"> <xsl:apply-templates select="$ParamVariables[@name = 'version']" mode="wwmode:variable-string-value" /> </xsl:variable> <xsl:variable name="subject" select="concat('Feedback for ', $vProduct, ' ', $vVersion, ' online help')"/> <xsl:variable name="body" select="'Please include the Help topic title in your feedback.'"/> <xsl:variable name="emailSuffix" select="concat('?subject=', $subject, '&body=', $body)"/> <xsl:variable name="emailString" select="concat(wwprojext:GetFormatSetting('company-email'), $emailSuffix)"/> <wwpage:Replacement name="company-email" value="Provide feedback on Unica documentation"/> <wwpage:Replacement name="company-email-href" value="{concat('mailto:', $emailString)}"/>
- We'll reorder the replacements so that we figure out our variables first and then pass those down to our company info template.
That should do it.