Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 875649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:18:18+00:00 2026-05-15T11:18:18+00:00

How to make the code more beautiful (compact)? <xsl:template match=part> <table class=part> <xsl:if test=name

  • 0

How to make the code more beautiful (compact)?

<xsl:template match="part">
    <table class="part">
        <xsl:if test="name != ''">
            <tr>
                <td>Название</td><td><xsl:value-of select="name"/></td>
            </tr>
        </xsl:if>
        <xsl:if test="model != ''">
            <tr>
                <td>Модель</td><td><xsl:value-of select="model"/></td>
            </tr>
        </xsl:if>
        <xsl:if test="year != ''">
            <tr>
                <td>Год</td><td><xsl:value-of select="year"/></td>
            </tr>
        </xsl:if>
        <xsl:if test="glass_type != ''">
            <tr>
                <td>Тип</td><td><xsl:value-of select="glass_type"/></td>
            </tr>
        </xsl:if>
        <xsl:if test="scancode != ''">
            <tr>
                <td>Сканкод</td><td><xsl:value-of select="scancode"/></td>
            </tr>
        </xsl:if>
        <xsl:if test="eurocode != ''">
            <tr>
                <td>Еврокод</td><td><xsl:value-of select="eurocode"/></td>
            </tr>
        </xsl:if>
        <xsl:if test="coment != ''">
            <tr>
                <td>Комментарий</td><td><xsl:value-of select="coment"/></td>
            </tr>
        </xsl:if>
        <xsl:if test="glass_size != ''">
            <tr>
                <td>Размер</td><td><xsl:value-of select="glass_size"/></td>
            </tr>
        </xsl:if>
        <xsl:if test="vendor != ''">
            <tr>
                <td>Производитель</td><td><xsl:value-of select="vendor"/></td>
            </tr>
        </xsl:if>
        <xsl:if test="trademark != ''">
            <tr>
                <td>Торговая марка</td><td><xsl:value-of select="trademark"/></td>
            </tr>
        </xsl:if>
        <xsl:if test="fprice != ''">
            <tr>
                <td>Цена</td><td><xsl:value-of select="fprice"/></td>
            </tr>
        </xsl:if>
    </table>
</xsl:template>

Update:

i wrote:

<my:translations xmlns:my="my:my">
    <w e="name" r="Название"/>
    <w e="model" r="Модель"/>
    <w e="year" r="Год"/>
    <w e="glass_type" r="Тип"/>
    <w e="scancode" r="Сканкод"/>
    <w e="eurocode" r="Еврокод"/>
    <w e="comment" r="Комментарий"/>
    <w e="glass_size" r="Размер"/>
    <w e="vendor" r="Производитель"/>
    <w e="trademark" r="Торговая марка"/>
    <w e="fprice" r="Цена"/>
</my:translations>

<xsl:value-of select="count(document('')//w)"/>

Gives 0.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T11:18:19+00:00Added an answer on May 15, 2026 at 11:18 am

    This transformation (44 lines of which 14 are the dictionary):

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:my="my:my"  exclude-result-prefixes="my">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:key name="kTranslate"
          match="w/@r" use="../@e"/>
    
     <my:translations>
       <w e="name" r="Название"/>
       <w e="model" r="Модель"/>
       <w e="year" r="Год"/>
       <w e="glass_type" r="Тип"/>
       <w e="scancode" r="Сканкод"/>
       <w e="eurocode" r="Еврокод"/>
       <w e="comment" r="Комментарий"/>
       <w e="glass_size" r="Размер"/>
       <w e="vendor" r="Производитель"/>
       <w e="trademark" r="Торговая марка"/>
       <w e="fprice" r="Цена"/>
     </my:translations>
    
     <xsl:template match="part">
       <table class="part">
        <xsl:apply-templates/>
       </table>
     </xsl:template>
    
     <xsl:template match="part/*">
       <xsl:variable name="vName" select="name()"/>
    
       <xsl:variable name="vRName">
         <xsl:for-each select="document('')">
             <xsl:value-of select="key('kTranslate', $vName)"/>
         </xsl:for-each>
       </xsl:variable>
    
      <tr>
        <td><xsl:value-of select="$vRName"/></td>
        <td><xsl:value-of select="."/></td>
      </tr>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on this XML document:

    <object>
      <part>
        <name>FooName</name>
        <model>FooName</model>
        <year>FooName</year>
        <glass_type>Fooglass_type</glass_type>
        <scancode >Fooscancode</scancode>
        <eurocode>Fooeurocode</eurocode>
        <comment>Foocomment</comment>
        <glass_size>Fooglass_size</glass_size>
        <vendor>Foovendor</vendor>
        <trademark>Footrademark</trademark>
        <fprice>Foofprice</fprice>
      </part>
    </object>
    

    produces the wanted, correct result:

    <table class="part">
       <tr>
          <td>Название</td>
          <td>FooName</td>
       </tr>
       <tr>
          <td>Модель</td>
          <td>FooName</td>
       </tr>
       <tr>
          <td>Год</td>
          <td>FooName</td>
       </tr>
       <tr>
          <td>Тип</td>
          <td>Fooglass_type</td>
       </tr>
       <tr>
          <td>Сканкод</td>
          <td>Fooscancode</td>
       </tr>
       <tr>
          <td>Еврокод</td>
          <td>Fooeurocode</td>
       </tr>
       <tr>
          <td>Комментарий</td>
          <td>Foocomment</td>
       </tr>
       <tr>
          <td>Размер</td>
          <td>Fooglass_size</td>
       </tr>
       <tr>
          <td>Производитель</td>
          <td>Foovendor</td>
       </tr>
       <tr>
          <td>Торговая марка</td>
          <td>Footrademark</td>
       </tr>
       <tr>
          <td>Цена</td>
          <td>Foofprice</td>
       </tr>
    </table>
    

    Do note:

    The dictionary is placed in a global namespaced element — only for demonstration purposes, in order to be able to present everything in a single stylesheet.

    In practical situations the dictionary will occupy its own XML file. Then it will be accessed by:

          <xsl:variable name="vRName">
             <xsl:for-each select="document('dictionaryFileName.xml')">
                 <xsl:value-of select="key('kTranslate', $vName)"/>
             </xsl:for-each>
           </xsl:variable>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a part of my code more fluent. I have a
Is there any way to make code more compact for this situation? // pseudocode
I need to make my code more compact. I have the following code: params[:investor][:profit]
I am trying to make my code more clear using the include function of
2 short questions based on trying to make my code more efficient (I think
I hate blocks. They are meant to make the code more concise, but I
Currently, I'm building several arrays in Powershell, but to make the code more portable,
I would like to make some of my code more monadic and to use
I'm trying to reorganize my code and make it more unobstrusive. Mainly, there is
To make this more clear, I'm going to put code samples: $file = fopen('filename.ext',

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.