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 7049295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:59:45+00:00 2026-05-28T02:59:45+00:00

I’m working on an XSLT file to transform an XML doc that represents a

  • 0

I’m working on an XSLT file to transform an XML doc that represents a table into SQL commands. The XML describes both the table’s columns and each row of data with the following structure:

<Table>
<ObjectAttributes>
  <AttributeDetail>
    <Name>COLNAME1</Name>
    ...
  </AttributeDetail>
  <AttributeDetail>
    <Name>COLNAME2</Name>
    ...
  </AttributeDetail>
  ...
</ObjectAttributes>
<Record RowID="00001">
  <Attributes>
    <Attr>
      <AttrName>COLNAME1</AttrName>
      <AttrValue>VALUE</AttrValue>
    </Attr>
    <Attr>
      <AttrName>COLNAME2</AttrName>
      <AttrValue>VALUE</AttrValue>
    </Attr>
    ...
  </Attributes>
</Record>
<Record RowID="00002">
  <Attributes>
    <Attr>
      <AttrName>COLNAME1</AttrName>
      <AttrValue>VALUE</AttrValue>
    </Attr>
    <Attr>
      <AttrName>COLNAME2</AttrName>
      <AttrValue>VALUE</AttrValue>
    </Attr>
    ...
  </Attributes>
</Record>
...
</Table>

I’ve written the following XSLT to create INSERT commands:

<xsl:for-each select="/Table/Record">
  <xsl:variable name="ThisRecord" select="."/>
  <Command>
    INSERT INTO <xsl:value-of select="../ObjectName"/>
      (ROWID, 
      <xsl:for-each select="../ObjectAttributes/AttributeDetail">
        <xsl:value-of select="Name"/>
        <xsl:if test="position() != last()">
          <xsl:text>, </xsl:text>
        </xsl:if>
      </xsl:for-each>) 
      VALUES 
      (<xsl:value-of select="@RowID"/>, 
      <xsl:for-each select="../ObjectAttributes/AttributeDetail">
        <xsl:text>'</xsl:text><xsl:value-of select="$ThisRecord/Attributes/Attr/AttrValue[../AttrName='COLNAME1']"/><xsl:text>'</xsl:text>
        <xsl:if test="position() != last()">
          <xsl:text>, </xsl:text>
        </xsl:if>
      </xsl:for-each>)
  </Command>
</xsl:for-each>

This works great except for the fact that I’m struggling to figure out how to replace the value for AttrName=” with the value that would result from:

<xsl:value-of select="Name"/>

I’ve tried replacing it with a variable, but this did not work:

<xsl:variable name="ThisAttr" select="Name"/>
<xsl:value-of select="$ThisRecord/Attributes/Attr/AttrValue[../AttrName='$ThisAttr']"/>

How can I fill in this attribute dynamically?

Thanks!

  • 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-28T02:59:46+00:00Added an answer on May 28, 2026 at 2:59 am

    You can reference the current context node with current():

    <xsl:value-of 
        select="$ThisRecord/Attributes/Attr[AttrName=current()/Name]/AttrValue"/>
    

    I should note that your variable approach would have worked without the quotes around the variable reference in AttrName='$ThisAttr'. You’re literally matching on the string $ThisAttr (i.e. not referencing any variable); you should have used AttrName=$ThisAttr (no quotes).

    That said, using current() is the better solution.

    (Note that I also re-arranged the expression steps so that no backtracking is required.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm parsing an XML file, the creators of it stuck in a bunch social
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.