Search

Sick of me yet? Here’s another question!
I have a “languages” section, with each language having an entry, and the language variables being stored in the columns. So the XML attached to the page looks like this:

<language>
    <pagination total-entries="2" total-pages="1" entries-per-page="20" current-page="1" />
    <section id="13" handle="languages">Languages</section>
    <entry id="119">
        <job-list-help handle="job-list-help">Job List Help</job-list-help>
        <oral-welsh-skills handle="oral-welsh-skills">Oral Welsh Skills</oral-welsh-skills>
        <written-welsh-skills handle="written-welsh-skills">Written Welsh Skills</written-welsh-skills>
        <job-reference handle="job-reference">Job Reference</job-reference>
        <job-list handle="job-list">Job List</job-list>
        <next handle="next">Next</next>
        <back handle="back">Back</back>
        <job-term handle="job-term">Job Term</job-term>
        <closing-date handle="closing-date">Closing Date</closing-date>
        <location handle="location">Location</location>
        <job-title handle="job-title">Job Title</job-title>
        <company handle="company">Company</company>
        <salary handle="salary">Salary</salary>
        <apply handle="apply">Apply</apply>
        <search handle="search">Search</search>
        <more-information handle="more-information">More Information</more-information>
        <page handle="page">Page</page>
        <language handle="english">English</language>
    </entry>
    <entry id="120">
        <oral-welsh-skills handle="sgiliau-iaith-ar-lafar">Sgiliau iaith ar lafar</oral-welsh-skills>
        <written-welsh-skills handle="sgiliau-iaith-ysgrfenedig">Sgiliau iaith ysgrfenedig</written-welsh-skills>
        <job-reference handle="cyfeirnod">Cyfeirnod</job-reference>
        <job-list handle="rhestr-swyddi">Rhestr Swyddi</job-list>
        <next handle="nesaf">nesaf</next>
        <back handle="n-and-ocirc-l">N&amp;amp;ocirc;l</back>
        <job-term handle="termaur-swydd">Termau'r Swydd</job-term>
        <closing-date handle="dyddiad-cau">Dyddiad Cau</closing-date>
        <location handle="lleoliad">Lleoliad</location>
        <job-title handle="teitl-swydd">Teitl Swydd</job-title>
        <company handle="cwmni">Cwmni</company>
        <salary handle="cyflog">Cyflog</salary>
        <more-information handle="mey-o-wybodaeth">Mey o wybodaeth</more-information>
        <page handle="tud">Tud</page>
        <language handle="welsh">Welsh</language>
    </entry>
</language>

Now what I want to do is take the user’s selected language and then assign all of its elements to identically named variables, so the language elements can be used throughout the layout.
Here’s what I have so far, which doesn’t work:

<xsl:template name="language">
    <xsl:for-each select="language/entry">
        <xsl:variable name="language-name" select="language/@handle"/>
        <xsl:choose>
            <xsl:when test="$language-name = $current-language">
                <xsl:for-each select="language/entry[language/@handle = $language-name]/*">
                    <xsl:variable name="@elementname" select="."/>
                </xsl:for-each>
            </xsl:when>
        </xsl:choose>
    </xsl:for-each>
</xsl:template>

I think it’s mostly just my lack of knowledge of selectors. For the variable assignment I really need it to name the variable the same as the element, so

<job-title handle="teitl-swydd">Teitl Swydd</job-title>

would become

<xsl:variable name="job-title" select="'Teitl Swydd'"/>

Once this is figured out it should prove to be quite a nice language system, but I’m having trouble finding anything like a cheat-sheet to help me with finding values from the XML, hence the many questions from me!
Many thanks to everyone who has helped me get into Symphony. I’m starting to understand it better, but clearly I still need help!

I’m not sure whether you can create variables with dynamic names like this — I’ve not seen it done before.

An alternative is to store the entire relevant language entry in a variable and grab the value using XPath each time:

<xsl:variable name="labels" select="language/entry[language/@handle = $current-language]"/>

This creates a variable $labels which refers to the entry node. To get a particular value:

<xsl:value-of select="$labels/job-title"/>

Perfect! That’s a much nicer solution, thanks very much nick :)

Hah funny,

You’d think we don’t communicate nickdunn.. Throlkim built most of the site I’m now adapting but is unavailable for the most part.. so good excercise for me to get to grips with the markup..

Will have a bash at this @handle suggestion for drop down entries and see what happens. booooom!

<label>
    <span class="label">
        <xsl:value-of select="$labels/hours"/>
    </span>
    <select name="fields[hours]">
        <option value="Full time">
            <xsl:value-of select="$labels/full-time"/>
        </option>
        <option value="Part time">
            <xsl:value-of select="$labels/part-time"/>
        </option>
     </select>
</label>

Trying to retrive the data that is entered in this column into my output field below..

<xsl:if test="hours != ''">
    <li>
        <div class="label">
            <xsl:value-of select="$labels/hours"/>: 
        </div>
        <div class="value">
            <xsl:value-of select="hours/item"/>
        </div>
    </li>
</xsl:if>

But the entered data is stored in 2 language entries depending on which language is selected I want the $labels/value to be present in the outputed xml

Make sense?

Why no code? I placed it in the code block bits.. but it did not appear?

Fixed. You just need to indent each line of code at least 4 spaces.

cool cheers :)

Make sense?

Without seeing your XML I’m afraid none at all!

<xsl:variable name="hours" select="hours/item/@handle"/>
<xsl:value-of select="*[name() = concat($labels, '/', $hours)]"/>

This should output the option selected from a drop down… in the current language stored in the $labels .. but it’s not working. whyyyyy

moonoo2

This is still not clear to me. Can you post the full XML and XSLT on pastie?

<xsl:value-of select="*[name() = concat($labels, '/', $hours)]"/>

What are the values of $labels and $hours? Here you’re trying to match a n element name that contains a forward slash, which isn’t valid e.g. foo/bar isn’t a valid element name. foo-bar is.

Is this what you’re after?

<xsl:value-of select="*[name() = $labels]/*[name() = $hours]"/>

Hi nickdunn..

Tried your suggestion and it did not seem to work.. just a blank entry.. wish I knew more about the subject to comment here. I can write it in plain english though..

I have 2 entries in the admin area.. One called Welsh and one called English.. inside these entries are identical sets of data as what Throlkim had requested help with at the top of this post.. So we have the data stores behind $labels/ as with your solution above.

Then I have a table called job with entries for submitting details on a job - such as start and end date, full time part time drop down options called “Full time and Part time” etc.. I want the data in the drop down to be bi-lingual so if I am on a welsh page.. the rendered xml looks in $labels for a value called Full time and outputs it’s result dependant on what language is currently in use.. at present I’m not sure if the $labels/full-time and $labels/part-time are being referenced in the options drop down.. just straight forward values that were typed with comma separation when building the job entries form..

Hope one or 2 things make sense here..

moonoo2

heres a look at a test page> here you can see the hours bit is emtpy..

Not sure how to publish the xml for you to see?

moonoo2

Well it says full time now cos I’ve reverted to the normal entry markup until I/we/the world can figure it out..

<xsl:value-of select="hours/item"/>

Not sure how to publish the xml for you to see?

On the page in question, add ?debug to the end of the URL. You’ll see the XML there. Copy it and post to pastie.


              

how do I get you to view it? I’ve copied it into pastie..

<script src='http://pastie.org/630528.js'></script>

You just post the link, like this: http://pastie.org/630528. Can you also pastie the full XSLT template(s)?

Sorry if I am a bit ignorant.. it’s an inherited project and the whole framework is new to me.. where would the xslt templates live? again novice with a thrist for knowledge and problem solving here!

moonoo2

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details