Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] Using xsl:key

From: Wendell Piez <wapiez@---------------->
To:
Date: 12/1/2006 4:12:00 PM
Siarom,



Picking up where David left off....



The entity business here is a red herring: the problem would be the 
same even if the entities weren't in play.



In effect, this is what you now have:



<RegLetter docpartnum="T11-30-06S" watermark="no"
status="preview">
   <Stuffer>
     <docinfo> ... </docinfo>

<lang type="EN">

   <infogroup>

      <fixedterms>

        <term id="caution" text="CAUTION"/>

        <term id="warning" text="WARNING"/>

        <term id="notice" text="NOTICE"/>

         ...

      </fixedterms>

    </infogroup>

    ...

      <warning><para>Missing translation...(Testing 
Warning)</para></warning>...

</lang>

<lang type="DE">

   <infogroup>

     <fixedterms>

       <term id="caution" text="WARNHINWEIS"/>

       <term id="warning" text="WARNUNG"/>

       <term id="notice" text="HINWEIS"/>

       ...

     </fixedterms>

   </infogroup>

   ...

     <warning><para>Missing translation...(Testing 
Warning)</para></warning>...

</lang>

(... and similarly for &T11-30-06S030132023_FR; and 
&T11-30-06S030132023_IT; etc.... )



  </Stuffer>
</RegLetter>

Then in your XSLT, your key declaration:



<xsl:key name="terms" match="term" use="@id"/>



and (in your template) the call to the key function:



<xsl:for-each select="key('terms','warning')">
  ...
</xsl:for-each>

Note: you have several term elements in your input (the English, the 
German, French, Italian and so on) whose @id value is the string 
"warning" -- so that's what the key function is returning.



What you need to do is set up your key so that it retrieves term 
elements not only on the basis of their @id value, but on the basis 
of what language they're in.



This information is available in each term element's ancestry ... 
from any given term element, the XPath "ancestor::lang/@type" 
retrieves an identifying string for each term's language, "EN", "DE", 
"FR" etc. (naturally these have to be unique but you're using 
standard codes to assure that).



You can create a key that combines this value with the value of its 
@id like so (a "compound key"):



<xsl:key name="terms" match="term" use="concat(ancestor::lang/@type, 
'-', @id)"/>



which results in this mapping of term elements to keys:



<term id="caution" text="CAUTION"/>     - 'EN-caution'
<term id="warning" text="WARNING"/>     - 'EN-warning'
<term id="notice" text="NOTICE"/>       - 'EN-notice'
<term id="caution" text="WARNHINWEIS"/> - 'DE-caution'
<term id="warning" text="WARNUNG"/>     - 'DE-warning'
<term id="notice" text="HINWEIS"/>      - 'DE-notice'

and so forth.



Then calling the key is straightforward



<xsl:for-each select="key('terms','EN-warning')">...</xsl:for-each>



which begs to be parameterized:



(probably at the top level)
<xsl:param name="lang-type" select="'EN'"/>
...

(then in your template)
<xsl:variable name="this-key" select="concat($lang-type,local-name())"/>
...
<xsl:for-each select="key('terms',$this-key)">...</xsl:for-each>

where the function 'local-name()' returns 'warning' for the warning 
element, 'caution' for the caution element, and so on.



This lets you use the same code for your warning, caution and notice 
elements (and any others you have where element names map cleanly to 
key values) in all the different languages.



I hope that helps,
Wendell

At 10:00 PM 11/30/2006, you wrote:
David,



Thanks for responding! I will provide more
information.

The way I have it setup is as follows:




I am going to call this XML snippet the master XML
because it calls the other language spaecific XMLs.
This is because I want one PDF output with all
languages.

<====master.xml=====>
<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet href="PCALetters.xsl"
type="text/xsl"?>
<!DOCTYPE RegLetter PUBLIC "-//SE Inc//DTD Regulatory
Letters XML//EN" "letters.dtd" [
<!ENTITY T11-30-06S030132023_EN SYSTEM
"T11-30-06S030132023-EN.xml">
<!ENTITY T11-30-06S030132023_DE SYSTEM
"T11-30-06S030132023-DE.xml">
<!ENTITY T11-30-06S030132023_FR SYSTEM
"T11-30-06S030132023-FR.xml">
<!ENTITY T11-30-06S030132023_IT SYSTEM
"T11-30-06S030132023-IT.xml">
]>

<RegLetter docpartnum="T11-30-06S" watermark="no"
status="preview">
   <Stuffer>
     <docinfo>
       <SEIlogo>
         <figureprint>
           <graphic fileref="seilogo.eps"/>
         </figureprint>
       </SEIlogo>
       <madeIn>Made in </madeIn>
       <copyright>&copy; Copyright...</copyright>
       <printedIn>Printed in </printedIn>
       <address>
         <addressline>B...4800 Harbor
Street...</addressline>
        </address>
     </docinfo>
&T11-30-06S030132023_EN;
&T11-30-06S030132023_DE;
&T11-30-06S030132023_FR;
&T11-30-06S030132023_IT;
  </Stuffer>
</RegLetter>

</====master.xml=====>



This is a snippet of the English XML file (first
output in the PDF)
<=====T11-30-06S030132023-EN.xml=====>

<?xml version="1.0" encoding="iso-8859-1"?>
<lang type="EN">
   <infogroup>
      <fixedterms>
        <term id="caution" text="CAUTION"/>
        <term id="warning" text="WARNING"/>
        <term id="notice" text="NOTICE"/>
         ...
      </fixedterms>
    </infogroup>
    ...
      <warning><para>Missing translation...(Testing
Warning)</para></warning>...
</lang>
</=====T11-30-06S030132023-EN.xml=====>

German XML snippet (2nd output in the PDF)
<=====T11-30-06S030132023-DE.xml=====>

<?xml version="1.0" encoding="iso-8859-1"?>
<lang type="DE">
   <infogroup>
     <fixedterms>
       <term id="caution" text="WARNHINWEIS"/>
       <term id="warning" text="WARNUNG"/>
       <term id="notice" text="HINWEIS"/>
       ...
     </fixedterms>
   </infogroup>
   ...
     <warning><para>Missing translation...(Testing
Warning)</para></warning>...
</lang>
</=====T11-30-06S030132023-DE.xml=====>

French XML snippet (3rd output in the PDF)
<=====T11-30-06S030132023-FR.xml=====>

<?xml version="1.0" encoding="iso-8859-1"?>
<lang type="FR">
   <infogroup>
     <fixedterms>
        <term id="caution" text="ATTENTION"/>
        <term id="warning" text="AVERTISSEMENT"/>
        <term id="notice" text="REMARQUE"/>
        ...
     </fixedterms>
   </infogroup>
   ...
     <warning><para>Missing translation...(Testing
Warning)</para></warning>...
</lang>
</=====T11-30-06S030132023-FR.xml=====>


Italian XML snippet (4th output in the PDF)
<=====T11-30-06S030132023-IT.xml=====>

<?xml version="1.0" encoding="iso-8859-1"?>
<lang type="IT">
   <infogroup>
      <fixedterms>
         <term id="caution" text="ATTENZIONE"/>
         <term id="warning" text="AVVERTENZA"/>
         <term id="notice" text="AVVISO"/>
         ...
      </fixedterms>
    </infogroup>
    ...
      <warning><para>Missing translation...(Testing
Warning)</para></warning>...
</lang>
</=====T11-30-06S030132023-IT.xml=====>

There are more languages with the same concept.



Here is the XSL Snippet:



<!--This is declared at the top of the FO style
sheet-->
<xsl:key name="terms" match="term" use="@id"/>
  <xsl:template match="/">

<xsl:template match="warning">
  <fo:block text-align="center">
     <fo:table border-style="solid" border-width="1pt"
space-after="2.5mm">
       <fo:table-column column-width="75%"/>
       <fo:table-body>
         <fo:table-row>
           <fo:table-cell padding-top="2mm">
             <fo:block text-align="center"
font-weight="bold">
                <fo:external-graphic
content-width=".3in" src="warning.eps"/>

                <xsl:for-each
select="key('terms','warning')">
                   <xsl:text>&#160;</xsl:text>
                   <xsl:value-of select="@text"/>
                </xsl:for-each>
             </fo:block>
           </fo:table-cell>
         </fo:table-row>
         <fo:table-row>
           <fo:table-cell padding-top="2mm"
padding-bottom="2mm" text-align="justify"
font-weight="bold"
start-indent="2mm" end-indent="2mm">
              <fo:block>
                <xsl:apply-templates/>
              </fo:block>
           </fo:table-cell>
         </fo:table-row>
       </fo:table-body>
     </fo:table>
  </fo:block>
</xsl:template>

Thanks again!



Siarom




======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent