Reputation: 13
My problem is as follows:
I am working on a XSL that takes it's info from different XML files, to get the task done.
I have a value and I want to see if the <Tag>
elements in one of the XML files holds the same value.
I tried by doing with for-each
, where I go through all the <Tag>
elements of the XML file and compare if their value equals to the value that I am looking for, but when I call the template, it doesn't work! If I take it out of the template, it at least goes inside the search loop.
Can anyone help please?
The XML file from which I am trying to retrieve the info, looks approximately as below:
<term-abbreviations>
<term name=".NET">
<abbreviation>The .NET framework is part of Windows and provides
a controlled environment for developing and running applications.
Programmers do not have to "reinvent the wheel" as the framework
provides a rich library of APIs that applications can use.</abbreviation>
</term>
</term-abbreviations>
and the xsl I wrote looks like this:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:w10="urn:schemas-microsoft-com:office:word"
xmlns:sl="http://schemas.microsoft.com/schemaLibrary/2003/core"
xmlns:aml="http://schemas.microsoft.com/aml/2001/core"
xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
xmlns:wsp="http://schemas.microsoft.com/office/word/2003/wordml/sp2"
xmlns:st1="urn:schemas-microsoft-com:office:smarttags"
xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<!-- TEMPLATE: ***GENERATE_NEWTERM_TABLE -->
<xsl:template name="Generate_newterm_table">
<xsl:for-each select="/document-properties/source-documents/*">
<xsl:for-each select="document(@name)/descendant::newTerm">
<xsl:call-template name="Generate_newterm_table_internal">
<xsl:with-param name="CurrentNewTerm" select="."/>
</xsl:call-template>
</xsl:for-each>
</xsl:for-each>
<!--<xsl:variable name="FilePath" select="/document-properties/abbreviation-document/document/@name"/>
<xsl:for-each select="document($FilePath)/descendant::term">
<xsl:choose>
<xsl:when test="(.=./@name)">
--><!--<xsl:when test="($TermToSearch=./@name)">--><!--
<w:p wsp:rsidR="00000000" wsp:rsidRDefault="00C06CD8">
<w:pPr>
<w:spacing w:before="60" w:after="60" />
<w:rPr>
<w:b />
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
</w:rPr>
<w:t>
<xsl:value-of select="concat(./@name, ' : found match')"/>
<xsl:value-of select="./abbreviation"/>
</w:t>
</w:r>
</w:p>
</xsl:when>
<xsl:otherwise>
<w:p wsp:rsidR="00000000" wsp:rsidRDefault="00C06CD8">
<w:pPr>
<w:spacing w:before="60" w:after="60" />
<w:rPr>
<w:b />
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
</w:rPr>
<w:t>
<xsl:value-of select="string('abbrv unavailable')"/>
</w:t>
</w:r>
</w:p>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>-->
</xsl:template>
<!-- END TEMPLATE: ***GENERATE_NEWTERM_TABLE -->
<!-- TEMPLATE: GENERATE_NEWTERM_TABLE_INTERNAL -->
<xsl:template name="Generate_newterm_table_internal">
<xsl:param name="CurrentNewTerm"/>
<w:tr wsp:rsidR="00000000">
<w:tblPrEx>
<w:tblCellMar>
<w:top w:w="0" w:type="dxa" />
<w:bottom w:w="0" w:type="dxa" />
</w:tblCellMar>
</w:tblPrEx>
<w:tc>
<w:tcPr>
<w:tcW w:w="2480" w:type="dxa" />
</w:tcPr>
<w:p wsp:rsidR="00000000" wsp:rsidRDefault="00C06CD8">
<w:pPr>
<w:spacing w:before="60" w:after="60" />
<w:rPr>
<w:b />
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
</w:rPr>
<w:t>
<xsl:value-of select="$CurrentNewTerm"/>
</w:t>
</w:r>
</w:p>
</w:tc>
<w:tc>
<w:tcPr>
<w:tcW w:w="2480" w:type="dxa" />
</w:tcPr>
<xsl:call-template name="FindAbbreviation">
<xsl:with-param name="TermToSearch" select="$CurrentNewTerm"/>
</xsl:call-template>
</w:tc>
</w:tr>
</xsl:template>
<!-- END TEMPLATE: GENERATE_NEWTERM_TABLE_INTERNAL -->
<!-- TEMPLATE: *** FIND ABBREVIATION *** -->
<xsl:template name="FindAbbreviation">
<xsl:param name="TermToSearch"/>
<!--<w:p wsp:rsidR="00000000" wsp:rsidRDefault="00C06CD8">
<w:pPr>
<w:spacing w:before="60" w:after="60" />
<w:rPr>
<w:b />
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
</w:rPr>
<w:t>
<xsl:value-of select="concat($TermToSearch, ' says', ' HI')"/>
</w:t>
</w:r>
</w:p>-->
<xsl:variable name="FilePath" select="/document-properties/abbreviation-document/document/@name"/>
<xsl:for-each select="document($FilePath)/descendant::term">
<xsl:choose>
<xsl:when test="($TermToSearch=./@name)">
<w:p wsp:rsidR="00000000" wsp:rsidRDefault="00C06CD8">
<w:pPr>
<w:spacing w:before="60" w:after="60" />
<w:rPr>
<w:b />
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
</w:rPr>
<w:t><xsl:value-of select="concat(./@name, ' : found match')"/>
<xsl:value-of select="./abbreviation"/></w:t>
</w:r>
</w:p>
</xsl:when>
<xsl:otherwise>
<w:p wsp:rsidR="00000000" wsp:rsidRDefault="00C06CD8">
<w:pPr>
<w:spacing w:before="60" w:after="60" />
<w:rPr>
<w:b />
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
</w:rPr>
<w:t><xsl:value-of select="string('abbrv unavailable')"/></w:t>
</w:r>
</w:p>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
<!-- END TEMPLATE: *** FIND ABBREVIATION *** -->
</xsl:stylesheet>
Upvotes: 0
Views: 1247
Reputation: 66723
In your <xsl:template name="FindAbbreviation">
, you are selecting /document-properties/abbreviation-document/document/@name
, but all of your XPATH expressions seem to expect to be relative from <document>
.
Change the XPATH select for $FilePath
to:
<xsl:variable name="FilePath"
select="/document-properties/abbreviation-document/document[@name]"/>
That will select the <document>
elements that have an @name
.
Upvotes: 1